Skip to content

Commit

Permalink
feat: added network id to user
Browse files Browse the repository at this point in the history
  • Loading branch information
acaldas committed Apr 15, 2024
1 parent 89c2a1c commit 908a50e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@vitejs/plugin-react": "^4.2.1",
"asar": "^3.2.0",
"autoprefixer": "^10.4.14",
"document-model-libs": "^1.25.0",
"document-model-libs": "^1.27.0",
"electron": "28.2.3",
"electron-playwright-helpers": "^1.7.1",
"eslint": "^8.56.0",
Expand Down Expand Up @@ -94,7 +94,7 @@
"@sentry/react": "^7.109.0",
"did-key-creator": "^1.2.0",
"document-drive": "^1.0.0-alpha.34",
"document-model": "^1.0.39",
"document-model": "^1.0.40",
"electron-is-dev": "^3.0.1",
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^8.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/components/editors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const DocumentEditor: React.FC<IProps> = ({
},
user: {
address: user.address,
networkId: user.networkId,
chainId: user.chainId,
},
signature: '',
Expand Down
13 changes: 9 additions & 4 deletions src/services/renown/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { User } from './types';
export type PKHDid = {
networkId: string;
chainId: number;
address: `0x${string}`;
};

export function parsePkhDid(did: string): Pick<User, 'chainId' | 'address'> {
export function parsePkhDid(did: string): PKHDid {
const parts = did.split(':');
if (!did.startsWith('did:pkh:') || parts.length !== 5) {
throw new Error('Invalid pkh did');
}
const [, , , chainIdStr, address] = parts;
const [, , networkId, chainIdStr, address] = parts;

if (!address.startsWith('0x')) {
throw new Error(`Invalid address: ${address}`);
Expand All @@ -18,6 +22,7 @@ export function parsePkhDid(did: string): Pick<User, 'chainId' | 'address'> {

return {
chainId,
address: address as `0x${string}`,
networkId,
address: address as PKHDid['address'],
};
}

0 comments on commit 908a50e

Please sign in to comment.