-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: kms-web3 #924
Merged
Merged
feat: kms-web3 #924
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8b59fa3
feat: kms-web3
simonas-notcat 4d29d22
fix(utils): test
simonas-notcat 37a2b2e
test: enabling all tests
simonas-notcat 9de1db5
fix: tests
simonas-notcat ce9f849
fix(test-react-app): setup
simonas-notcat 41cb81f
fix(kms-web3): remove keyStore dependency
simonas-notcat 057fcbf
test: kms-web3
simonas-notcat 1163f1f
test: update ganache
simonas-notcat f5dfa89
fix(credential-eip712): remove EIP712Domain at kms
simonas-notcat 7d47d07
test(test-react-app): fixed setup
simonas-notcat 0d5e987
test: remove unused imports
simonas-notcat fa89dce
fix: move Eip712Payload to key-manager
simonas-notcat 0d6e701
docs(kms-web3): constructor params
simonas-notcat 17b7860
Merge branch 'next' into feature/kms-web3
simonas-notcat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { IAgentOptions, IDIDManager, IResolver, MinimalImportableKey, TAgent } from '../../packages/core/src' | ||
import { getChainIdForDidEthr, resolveDidOrThrow, mapIdentifierKeysToDoc } from '../../packages/utils/src' | ||
|
||
type ConfiguredAgent = TAgent<IResolver & IDIDManager> | ||
|
||
export default (testContext: { | ||
getAgent: (options?: IAgentOptions) => ConfiguredAgent | ||
setup: (options?: IAgentOptions) => Promise<boolean> | ||
tearDown: () => Promise<boolean> | ||
}) => { | ||
describe('utilities', () => { | ||
let agent: ConfiguredAgent | ||
|
||
beforeAll(async () => { | ||
await testContext.setup() | ||
agent = testContext.getAgent() | ||
return true | ||
}) | ||
afterAll(testContext.tearDown) | ||
|
||
it('should get chainId for ethr did', async () => { | ||
const didUrl = 'did:ethr:rinkeby:0xb09b66026ba5909a7cfe99b76875431d2b8d5190' | ||
const didDoc = await resolveDidOrThrow(didUrl, {agent}) | ||
if (didDoc.verificationMethod) { | ||
const chainId = getChainIdForDidEthr(didDoc.verificationMethod[0]) | ||
expect(chainId).toEqual(4) | ||
} | ||
}) | ||
|
||
it('should map identifier keys to did doc', async () => { | ||
const account = `0xb09b66026ba5909a7cfe99b76875431d2b8d5190` | ||
const did = `did:ethr:0x4:${account}` | ||
const controllerKeyId = `metamask-${account}` | ||
await agent.didManagerImport({ | ||
did, | ||
provider: 'did:ethr:rinkeby', | ||
controllerKeyId, | ||
keys: [{ | ||
kid: controllerKeyId, | ||
type: 'Secp256k1', | ||
kms: 'web3', | ||
privateKeyHex: '', | ||
publicKeyHex: '', | ||
meta: { | ||
account, | ||
provider: 'metamask', | ||
algorithms: [ | ||
'eth_signMessage', | ||
'eth_signTypedData', | ||
] | ||
}, | ||
} as MinimalImportableKey], | ||
}) | ||
|
||
const identifier = await agent.didManagerGet({ did }) | ||
const extendedKeys = await mapIdentifierKeysToDoc(identifier, 'verificationMethod', { agent }) | ||
expect(extendedKeys[0].meta.verificationMethod?.blockchainAccountId?.toLocaleLowerCase()).toEqual(`eip155:4:${account}`) | ||
|
||
}) | ||
}) | ||
} |
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,91 @@ | ||
import { IAgentOptions, IDIDManager, IIdentifier, IKeyManager, IResolver, MinimalImportableKey, TAgent, VerifiableCredential } from '../../packages/core/src' | ||
|
||
type ConfiguredAgent = TAgent<IResolver & IDIDManager & IKeyManager> | ||
|
||
export default (testContext: { | ||
getAgent: (options?: IAgentOptions) => ConfiguredAgent | ||
setup: (options?: IAgentOptions) => Promise<boolean> | ||
tearDown: () => Promise<boolean> | ||
}) => { | ||
describe('web3', () => { | ||
let agent: ConfiguredAgent | ||
let identifier: IIdentifier | ||
let verifiableCredential: VerifiableCredential | ||
|
||
beforeAll(async () => { | ||
await testContext.setup() | ||
agent = testContext.getAgent() | ||
return true | ||
}) | ||
afterAll(testContext.tearDown) | ||
|
||
it('should import ganache did', async () => { | ||
const account = `0x7e5f4552091a69125d5dfcb7b8c2659029395bdf` | ||
const did = `did:ethr:ganache:${account}` | ||
const controllerKeyId = `ganache-${account}` | ||
identifier = await agent.didManagerImport({ | ||
did, | ||
provider: 'did:ethr:ganache', | ||
controllerKeyId, | ||
keys: [{ | ||
kid: controllerKeyId, | ||
type: 'Secp256k1', | ||
kms: 'web3', | ||
privateKeyHex: '', | ||
publicKeyHex: '', | ||
meta: { | ||
account, | ||
provider: 'ganache', | ||
algorithms: [ | ||
'eth_signMessage', | ||
'eth_signTypedData', | ||
] | ||
}, | ||
} as MinimalImportableKey], | ||
}) | ||
}) | ||
|
||
// getting error: The method personal_sign does not exist/is not available | ||
// https://github.com/trufflesuite/ganache/issues/995 | ||
it.skip('should sign a message', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these 2 tests should not be skipped since they represent the base functionality of this package. |
||
if (identifier.controllerKeyId) { | ||
const signature = await agent.keyManagerSign({ | ||
data: 'Hello world', | ||
keyRef: identifier.controllerKeyId, | ||
algorithm: 'eth_signMessage' | ||
}) | ||
expect(signature).toBeTruthy() | ||
} | ||
}) | ||
|
||
it('should create verifiable credential with EthereumEip712Signature2021 proof type', async () => { | ||
verifiableCredential = await agent.createVerifiableCredential({ | ||
credential: { | ||
issuer: { id: identifier.did }, | ||
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://example.com/1/2/3'], | ||
type: ['VerifiableCredential', 'Custom'], | ||
issuanceDate: new Date().toISOString(), | ||
credentialSubject: { | ||
id: 'did:web:example.com', | ||
you: 'Rock', | ||
} | ||
}, | ||
proofFormat: 'EthereumEip712Signature2021', | ||
}) | ||
|
||
expect(verifiableCredential).toHaveProperty('proof.proofValue') | ||
expect(verifiableCredential['@context']).toEqual([ | ||
'https://www.w3.org/2018/credentials/v1', | ||
'https://example.com/1/2/3', | ||
]) | ||
expect(verifiableCredential['type']).toEqual(['VerifiableCredential', 'Custom']) | ||
|
||
const hash = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential }) | ||
expect(typeof hash).toEqual('string') | ||
|
||
const verifiableCredential2 = await agent.dataStoreGetVerifiableCredential({ hash }) | ||
expect(verifiableCredential).toEqual(verifiableCredential2) | ||
|
||
}) | ||
}) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not to be fixed in this PR, but definitely before the next release, so I'm writing this as a reference.
This import seems crucial to the way the web3-kms will behave.
The key metadata, the
controllerKeyId
andkid
of the key must all align properly for this to work.Also, if web3 providers change, there should also be some update to the managed DIDs and keys from
@veramo/did-manager
/@veramo/key-manager