-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: remove old website (#136) * chore: removed workflows, website * chore: update lock file and some other fixes * feat: update packages to esm (#135) * feat: esm ssi-snap-types * feat: esm connector * fix: add readme to output * chore: update connector deps * chore: lintstaged.cjs * chore: more lintstaged.cjs * chore: connector lintstaged.cjs * feat: esm vcmanager and update configs * feat: esm utils * feat: update tests * chore: deps * fix: build dapp * fix: docs * fix: fixes config issues * fix: fixes config issues * fix: resolve last issues * feat: replaced get currentAccount func * chore: update dev deps (#144) * chore: update dev deps * fix: fixes lockfile * fix: fixes lockfile * chore: update nodejs and pnpm * chore: remove patch * chore: add back snap types patch * fix: should fix CI workflow * fix: set pnpm version in main CI * fix: try fixing symlink issues * fix: tests for new getCurrentAddress * feat: add did:jwk provider from veramo * feat: replace did jwk and pkh creation * chore: update pnpm-lock.yaml * fix: post rebase fixes * fix: dependencies issue * fix: tests and params objects * fix: update metamask snaps-types patch * fix: update some code and a lot of tests --------- Co-authored-by: Tadej <[email protected]>
- Loading branch information
1 parent
7fc29dc
commit d1fc4fe
Showing
36 changed files
with
1,592 additions
and
1,160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,4 +78,4 @@ nx-cloud.env | |
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
snap/patches/cross-fetch+3.1.5.patch | ||
.vscode |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,7 @@ | |
"pnpm": { | ||
"patchedDependencies": { | ||
"[email protected]": "patches/[email protected]", | ||
"@metamask/snaps-types@0.28.0": "patches/@metamask__snaps-types@0.28.0.patch" | ||
"@metamask/snaps-types@0.30.0": "patches/@metamask__snaps-types@0.30.0.patch" | ||
}, | ||
"allowNonAppliedPatches": true | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import { | ||
JwkDidSupportedKeyTypes, | ||
KeyUse, | ||
SupportedKeyTypes, | ||
} from '@veramo/did-provider-jwk'; | ||
import { | ||
bytesToBase64url, | ||
encodeJoseBlob, | ||
extractPublicKeyHex, | ||
hexToBytes, | ||
} from '@veramo/utils'; | ||
import type { JsonWebKey, VerificationMethod } from 'did-resolver'; | ||
import elliptic from 'elliptic'; | ||
|
||
import { SSISnapState } from '../../interfaces'; | ||
import type { Agent } from '../../veramo/setup'; | ||
|
||
const EC = elliptic.ec; | ||
|
||
export function getKeyUse( | ||
keyType: JwkDidSupportedKeyTypes, | ||
passedKeyUse?: KeyUse | ||
): KeyUse { | ||
if (passedKeyUse) { | ||
if (passedKeyUse !== 'sig' && passedKeyUse !== 'enc') { | ||
throw new Error('illegal_argument: Key use must be sig or enc'); | ||
} | ||
if (passedKeyUse === 'sig' && keyType === 'X25519') { | ||
throw new Error( | ||
'illegal_argument: X25519 keys cannot be used for signing' | ||
); | ||
} | ||
if (passedKeyUse === 'enc' && keyType === 'Ed25519') { | ||
throw new Error( | ||
'illegal_argument: Ed25519 keys cannot be used for encryption' | ||
); | ||
} | ||
return passedKeyUse; | ||
} | ||
switch (keyType) { | ||
case 'Secp256k1': | ||
case 'Secp256r1': | ||
case 'Ed25519': | ||
return 'sig'; | ||
case 'X25519': | ||
return 'enc'; | ||
default: | ||
throw new Error('illegal_argument: Unknown key type'); | ||
} | ||
} | ||
|
||
export function isJWK(data: unknown): data is JsonWebKey { | ||
if ( | ||
typeof data === 'object' && | ||
data && | ||
'crv' in data && | ||
typeof data.crv === 'string' && | ||
'kty' in data && | ||
'x' in data && | ||
typeof data.x === 'string' && | ||
((data.kty === 'EC' && 'y' in data && typeof data.y === 'string') || | ||
(data.kty === 'OKP' && !('y' in data))) | ||
) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function createJWK( | ||
keyType: JwkDidSupportedKeyTypes, | ||
pubKey: string | Uint8Array, | ||
passedKeyUse?: KeyUse | ||
): JsonWebKey | undefined { | ||
const keyUse = getKeyUse(keyType, passedKeyUse); | ||
switch (keyType) { | ||
case SupportedKeyTypes.Secp256k1: { | ||
const ctx = new EC('secp256k1'); | ||
const pubPoint = ctx.keyFromPublic(pubKey, 'hex').getPublic(); | ||
const x = pubPoint.getX(); | ||
const y = pubPoint.getY(); | ||
|
||
return { | ||
alg: 'ES256K', | ||
crv: 'secp256k1', | ||
kty: 'EC', | ||
...(keyUse && { use: keyUse }), | ||
x: bytesToBase64url(hexToBytes(x.toString('hex'))), | ||
y: bytesToBase64url(hexToBytes(y.toString('hex'))), | ||
} as JsonWebKey; | ||
} | ||
case SupportedKeyTypes.Secp256r1: { | ||
const ctx = new EC('p256'); | ||
const pubPoint = ctx.keyFromPublic(pubKey, 'hex').getPublic(); | ||
const x = pubPoint.getX(); | ||
const y = pubPoint.getY(); | ||
|
||
return { | ||
alg: 'ES256', | ||
crv: 'P-256', | ||
kty: 'EC', | ||
...(keyUse && { use: keyUse }), | ||
x: bytesToBase64url(hexToBytes(x.toString('hex'))), | ||
y: bytesToBase64url(hexToBytes(y.toString('hex'))), | ||
} as JsonWebKey; | ||
} | ||
case SupportedKeyTypes.Ed25519: | ||
return { | ||
alg: 'EdDSA', | ||
crv: 'Ed25519', | ||
kty: 'OKP', | ||
...(keyUse && { use: keyUse }), | ||
x: bytesToBase64url( | ||
typeof pubKey === 'string' ? hexToBytes(pubKey) : pubKey | ||
), | ||
} as JsonWebKey; | ||
case SupportedKeyTypes.X25519: | ||
return { | ||
alg: 'ECDH-ES', | ||
crv: 'X25519', | ||
kty: 'OKP', | ||
...(keyUse && { use: keyUse }), | ||
x: bytesToBase64url( | ||
typeof pubKey === 'string' ? hexToBytes(pubKey) : pubKey | ||
), | ||
} as JsonWebKey; | ||
default: | ||
throw new Error(`not_supported: Failed to create JWK using ${keyType}`); | ||
} | ||
} | ||
|
||
export function generateJwkFromVerificationMethod( | ||
keyType: JwkDidSupportedKeyTypes, | ||
key: VerificationMethod, | ||
keyUse?: KeyUse | ||
) { | ||
return createJWK(keyType, extractPublicKeyHex(key), keyUse); | ||
} | ||
|
||
export async function getDidJwkIdentifier( | ||
state: SSISnapState, | ||
account: string, | ||
agent?: Agent | ||
): Promise<string> { | ||
if (agent) { | ||
const identifier = await agent.didManagerCreate({ | ||
provider: 'did:jwk', | ||
options: { | ||
keyType: 'Secp256k1', | ||
}, | ||
}); | ||
return identifier.did; | ||
} | ||
const { publicKey } = state.accountState[account]; | ||
const jwk = generateJwkFromVerificationMethod('Secp256k1', { | ||
publicKeyHex: publicKey, | ||
} as VerificationMethod); | ||
const jwkBase64url = encodeJoseBlob(jwk as object); | ||
return `did:jwk:${jwkBase64url}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import { MetaMaskInpageProvider } from '@metamask/providers'; | ||
import { SnapsGlobalObject } from '@metamask/snaps-types'; | ||
import { BIP44CoinTypeNode } from '@metamask/key-tree'; | ||
|
||
import { SSISnapState } from '../../interfaces'; | ||
import { ApiParams } from '../../interfaces'; | ||
import { getCurrentDid } from '../../utils/didUtils'; | ||
|
||
export async function getDid(params: { | ||
state: SSISnapState; | ||
snap: SnapsGlobalObject; | ||
account: string; | ||
ethereum: MetaMaskInpageProvider; | ||
}): Promise<string> { | ||
const res = await getCurrentDid(params); | ||
return res; | ||
export async function getDid(params: ApiParams): Promise<string> { | ||
return getCurrentDid({ | ||
ethereum: params.ethereum, | ||
snap: params.snap, | ||
state: params.state, | ||
account: params.account, | ||
bip44CoinTypeNode: params.bip44CoinTypeNode as BIP44CoinTypeNode, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { SetCurrentAccountRequestParams } from '@blockchain-lab-um/ssi-snap-types'; | ||
|
||
import { ApiParams } from '../../interfaces'; | ||
import { updateSnapState } from '../../utils/stateUtils'; | ||
|
||
export async function setCurrentAccount( | ||
params: ApiParams, | ||
args: SetCurrentAccountRequestParams | ||
): Promise<boolean> { | ||
const { state, snap } = params; | ||
const { currentAccount } = args; | ||
state.currentAccount = currentAccount; | ||
await updateSnapState(snap, state); | ||
return true; | ||
} |
Oops, something went wrong.