-
Notifications
You must be signed in to change notification settings - Fork 204
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: add generic did resolver #554
Merged
TimoGlastra
merged 20 commits into
openwallet-foundation:main
from
TimoGlastra:feat/did-resolver
Jan 5, 2022
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
382b143
feat(core): initial did resolver functionality
TimoGlastra 7ec0a5e
feat: did:key, did:web, did:sov resolver
TimoGlastra 4845b8f
test: add did:key tests for ed25519 and x25519
TimoGlastra 201c9ea
test: add did:key tests for bls12381g1 bls12381g2
TimoGlastra dd06255
fix: update indy-sdk types to 1.16.8
TimoGlastra 42209c1
feat: e2e did flow
TimoGlastra 9dbab6a
fix: did key improvements
TimoGlastra 9143829
test: remove did:web e2e test as it needs internet
TimoGlastra 9fca710
fix: improve did:sov resolver and tests
TimoGlastra 447d0f3
test: add test for did resolver service
TimoGlastra d9cd4ad
fix: error message for did key
TimoGlastra cee29ce
Merge remote-tracking branch 'upstream/main' into feat/did-resolver
TimoGlastra a8459f5
fix: fixes from validate
TimoGlastra 010dd8f
refactor: class transformer for diddoc validation
TimoGlastra 40dbc37
Merge branch 'main' into feat/did-resolver
TimoGlastra a92476b
Merge branch 'main' into feat/did-resolver
TimoGlastra d113ac7
fix: import buffer
TimoGlastra f0d9fdf
test: cleaner test descriptions for did key
TimoGlastra 2763812
refactor: remove logic from index file
TimoGlastra c50035d
Merge remote-tracking branch 'upstream/main' into feat/did-resolver
TimoGlastra 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { DidResolutionOptions } from './types' | ||
|
||
import { Lifecycle, scoped } from 'tsyringe' | ||
|
||
import { DidResolverService } from './services/DidResolverService' | ||
|
||
@scoped(Lifecycle.ContainerScoped) | ||
export class DidsModule { | ||
private resolverService: DidResolverService | ||
|
||
public constructor(resolverService: DidResolverService) { | ||
this.resolverService = resolverService | ||
} | ||
|
||
public resolve(didUrl: string, options?: DidResolutionOptions) { | ||
return this.resolverService.resolve(didUrl, options) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
packages/core/src/modules/dids/__tests__/DidKeyBls12381G1.test.ts
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,63 @@ | ||
import { BufferEncoder } from '../../../utils/BufferEncoder' | ||
import { JsonTransformer } from '../../../utils/JsonTransformer' | ||
import { Buffer } from '../../../utils/buffer' | ||
import { DidKey, KeyType } from '../domain/DidKey' | ||
|
||
import didKeyBls12381g1Fixture from './__fixtures__/didKeyBls12381g1.json' | ||
|
||
const TEST_BLS12381G1_BASE58_KEY = '6FywSzB5BPd7xehCo1G4nYHAoZPMMP3gd4PLnvgA6SsTsogtz8K7RDznqLpFPLZXAE' | ||
const TEST_BLS12381G1_FINGERPRINT = 'z3tEFALUKUzzCAvytMHX8X4SnsNsq6T5tC5Zb18oQEt1FqNcJXqJ3AA9umgzA9yoqPBeWA' | ||
const TEST_BLS12381G1_DID = `did:key:${TEST_BLS12381G1_FINGERPRINT}` | ||
const TEST_BLS12381G1_KEY_ID = `${TEST_BLS12381G1_DID}#${TEST_BLS12381G1_FINGERPRINT}` | ||
const TEST_BLS12381G1_PREFIX_BYTES = Buffer.concat([ | ||
new Uint8Array([234, 1]), | ||
BufferEncoder.fromBase58(TEST_BLS12381G1_BASE58_KEY), | ||
]) | ||
|
||
describe('DidKey', () => { | ||
describe('bls12381g1', () => { | ||
it('creates a DidKey instance from public key bytes and bls12381g1 key type', async () => { | ||
const publicKeyBytes = BufferEncoder.fromBase58(TEST_BLS12381G1_BASE58_KEY) | ||
|
||
const didKey = DidKey.fromPublicKey(publicKeyBytes, KeyType.BLS12381G1) | ||
|
||
expect(didKey.did).toBe(TEST_BLS12381G1_DID) | ||
}) | ||
|
||
it('creates a DidKey instance from a base58 encoded public key and bls12381g1 key type', async () => { | ||
const didKey = DidKey.fromPublicKeyBase58(TEST_BLS12381G1_BASE58_KEY, KeyType.BLS12381G1) | ||
|
||
expect(didKey.did).toBe(TEST_BLS12381G1_DID) | ||
}) | ||
|
||
it('creates a DidKey instance from a fingerprint', async () => { | ||
const didKey = DidKey.fromFingerprint(TEST_BLS12381G1_FINGERPRINT) | ||
|
||
expect(didKey.did).toBe(TEST_BLS12381G1_DID) | ||
}) | ||
|
||
it('creates a DidKey instance from a did', async () => { | ||
const didKey = DidKey.fromDid(TEST_BLS12381G1_DID) | ||
|
||
expect(didKey.publicKeyBase58).toBe(TEST_BLS12381G1_BASE58_KEY) | ||
}) | ||
|
||
it('should correctly calculate the getter properties', async () => { | ||
const didKey = DidKey.fromDid(TEST_BLS12381G1_DID) | ||
|
||
expect(didKey.fingerprint).toBe(TEST_BLS12381G1_FINGERPRINT) | ||
expect(didKey.did).toBe(TEST_BLS12381G1_DID) | ||
expect(didKey.publicKeyBase58).toBe(TEST_BLS12381G1_BASE58_KEY) | ||
expect(didKey.publicKey).toEqual(BufferEncoder.fromBase58(TEST_BLS12381G1_BASE58_KEY)) | ||
expect(didKey.keyType).toBe(KeyType.BLS12381G1) | ||
expect(didKey.keyId).toBe(TEST_BLS12381G1_KEY_ID) | ||
expect(didKey.prefixedPublicKey.equals(TEST_BLS12381G1_PREFIX_BYTES)).toBe(true) | ||
}) | ||
|
||
it('should return a valid did:key did document for the did', async () => { | ||
const didKey = DidKey.fromDid(TEST_BLS12381G1_DID) | ||
|
||
expect(JsonTransformer.toJSON(didKey.didDocument)).toMatchObject(didKeyBls12381g1Fixture) | ||
}) | ||
}) | ||
}) |
100 changes: 100 additions & 0 deletions
100
packages/core/src/modules/dids/__tests__/DidKeyBls12381G1G2.test.ts
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,100 @@ | ||
import { BufferEncoder } from '../../../utils/BufferEncoder' | ||
import { JsonTransformer } from '../../../utils/JsonTransformer' | ||
import { Buffer } from '../../../utils/buffer' | ||
import { DidKey, KeyType } from '../domain/DidKey' | ||
|
||
import didKeyBls12381g1g2Fixture from './__fixtures__/didKeyBls12381g1g2.json' | ||
|
||
const TEST_BLS12381G1G2_BASE58_KEY = | ||
'AQ4MiG1JKHmM5N4CgkF9uQ484PHN7gXB3ctF4ayL8hT6FdD6rcfFS3ZnMNntYsyJBckfNPf3HL8VU8jzgyT3qX88Yg3TeF2NkG2aZnJDNnXH1jkJStWMxjLw22LdphqAj1rSorsDhHjE8Rtz61bD6FP9aPokQUDVpZ4zXqsXVcxJ7YEc66TTLTTPwQPS7uNM4u2Fs' | ||
const TEST_BLS12381G1G2_FINGERPRINT = | ||
'z5TcESXuYUE9aZWYwSdrUEGK1HNQFHyTt4aVpaCTVZcDXQmUheFwfNZmRksaAbBneNm5KyE52SdJeRCN1g6PJmF31GsHWwFiqUDujvasK3wTiDr3vvkYwEJHt7H5RGEKYEp1ErtQtcEBgsgY2DA9JZkHj1J9HZ8MRDTguAhoFtR4aTBQhgnkP4SwVbxDYMEZoF2TMYn3s' | ||
const TEST_BLS12381G1G2_DID = `did:key:${TEST_BLS12381G1G2_FINGERPRINT}` | ||
|
||
const TEST_BLS12381G1_BASE58_KEY = '7BVES4h78wzabPAfMhchXyH5d8EX78S5TtzePH2YkftWcE6by9yj3NTAv9nsyCeYch' | ||
const TEST_BLS12381G1_FINGERPRINT = 'z3tEG5qmJZX29jJSX5kyhDR5YJNnefJFdwTxRqk6zbEPv4Pf2xF12BpmXv9NExxSRFGfxd' | ||
const TEST_BLS12381G1_DID = `did:key:${TEST_BLS12381G1_FINGERPRINT}` | ||
|
||
const TEST_BLS12381G2_BASE58_KEY = | ||
'26d2BdqELsXg7ZHCWKL2D5Y2S7mYrpkdhJemSEEvokd4qy4TULJeeU44hYPGKo4x4DbBp5ARzkv1D6xuB3bmhpdpKAXuXtode67wzh9PCtW8kTqQhH19VSiFZkLNkhe9rtf3' | ||
const TEST_BLS12381G2_FINGERPRINT = | ||
'zUC7LTa4hWtaE9YKyDsMVGiRNqPMN3s4rjBdB3MFi6PcVWReNfR72y3oGW2NhNcaKNVhMobh7aHp8oZB3qdJCs7RebM2xsodrSm8MmePbN25NTGcpjkJMwKbcWfYDX7eHCJjPGM' | ||
const TEST_BLS12381G2_DID = `did:key:${TEST_BLS12381G2_FINGERPRINT}` | ||
|
||
const TEST_BLS12381G1G2_PREFIX_BYTES = Buffer.concat([ | ||
new Uint8Array([238, 1]), | ||
BufferEncoder.fromBase58(TEST_BLS12381G1G2_BASE58_KEY), | ||
]) | ||
|
||
describe('DidKey', () => { | ||
describe('bls12381g1g2', () => { | ||
it('creates a DidKey instance from public key bytes and bls12381g1g2 key type', async () => { | ||
const publicKeyBytes = BufferEncoder.fromBase58(TEST_BLS12381G1G2_BASE58_KEY) | ||
|
||
const didKey = DidKey.fromPublicKey(publicKeyBytes, KeyType.BLS12381G1G2) | ||
|
||
expect(didKey.did).toBe(TEST_BLS12381G1G2_DID) | ||
}) | ||
|
||
it('creates a DidKey instance from a base58 encoded public key and bls12381g1g2 key type', async () => { | ||
const didKey = DidKey.fromPublicKeyBase58(TEST_BLS12381G1G2_BASE58_KEY, KeyType.BLS12381G1G2) | ||
|
||
expect(didKey.did).toBe(TEST_BLS12381G1G2_DID) | ||
}) | ||
|
||
it('creates a DidKey instance from a fingerprint', async () => { | ||
const didKey = DidKey.fromFingerprint(TEST_BLS12381G1G2_FINGERPRINT) | ||
|
||
expect(didKey.did).toBe(TEST_BLS12381G1G2_DID) | ||
}) | ||
|
||
it('creates a DidKey instance from a did', async () => { | ||
const didKey = DidKey.fromDid(TEST_BLS12381G1G2_DID) | ||
|
||
expect(didKey.publicKeyBase58).toBe(TEST_BLS12381G1G2_BASE58_KEY) | ||
}) | ||
|
||
it('should correctly calculate the getter properties', async () => { | ||
const didKey = DidKey.fromDid(TEST_BLS12381G1G2_DID) | ||
|
||
expect(didKey.fingerprint).toBe(TEST_BLS12381G1G2_FINGERPRINT) | ||
expect(didKey.did).toBe(TEST_BLS12381G1G2_DID) | ||
expect(didKey.publicKeyBase58).toBe(TEST_BLS12381G1G2_BASE58_KEY) | ||
expect(didKey.publicKey).toEqual(BufferEncoder.fromBase58(TEST_BLS12381G1G2_BASE58_KEY)) | ||
expect(didKey.keyType).toBe(KeyType.BLS12381G1G2) | ||
expect(didKey.prefixedPublicKey.equals(TEST_BLS12381G1G2_PREFIX_BYTES)).toBe(true) | ||
}) | ||
|
||
it('should return a valid did:key did document for the did', async () => { | ||
const didKey = DidKey.fromDid(TEST_BLS12381G1G2_DID) | ||
|
||
expect(JsonTransformer.toJSON(didKey.didDocument)).toMatchObject(didKeyBls12381g1g2Fixture) | ||
}) | ||
|
||
it('should correctly go from g1g2 to g1', async () => { | ||
const g1g2DidKey = DidKey.fromDid(TEST_BLS12381G1G2_DID) | ||
|
||
const g1PublicKey = g1g2DidKey.publicKey.slice(0, 48) | ||
const g1DidKey = DidKey.fromPublicKey(g1PublicKey, KeyType.BLS12381G1) | ||
|
||
expect(g1DidKey.fingerprint).toBe(TEST_BLS12381G1_FINGERPRINT) | ||
expect(g1DidKey.did).toBe(TEST_BLS12381G1_DID) | ||
expect(g1DidKey.publicKeyBase58).toBe(TEST_BLS12381G1_BASE58_KEY) | ||
expect(g1DidKey.publicKey).toEqual(BufferEncoder.fromBase58(TEST_BLS12381G1_BASE58_KEY)) | ||
expect(g1DidKey.keyType).toBe(KeyType.BLS12381G1) | ||
}) | ||
|
||
it('should correctly go from g1g2 to g2', async () => { | ||
const g1g2DidKey = DidKey.fromDid(TEST_BLS12381G1G2_DID) | ||
|
||
const g2PublicKey = g1g2DidKey.publicKey.slice(48) | ||
const g2DidKey = DidKey.fromPublicKey(g2PublicKey, KeyType.BLS12381G2) | ||
|
||
expect(g2DidKey.fingerprint).toBe(TEST_BLS12381G2_FINGERPRINT) | ||
expect(g2DidKey.did).toBe(TEST_BLS12381G2_DID) | ||
expect(g2DidKey.publicKeyBase58).toBe(TEST_BLS12381G2_BASE58_KEY) | ||
expect(g2DidKey.publicKey).toEqual(BufferEncoder.fromBase58(TEST_BLS12381G2_BASE58_KEY)) | ||
expect(g2DidKey.keyType).toBe(KeyType.BLS12381G2) | ||
}) | ||
}) | ||
}) |
65 changes: 65 additions & 0 deletions
65
packages/core/src/modules/dids/__tests__/DidKeyBls12381G2.test.ts
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,65 @@ | ||
import { BufferEncoder } from '../../../utils/BufferEncoder' | ||
import { JsonTransformer } from '../../../utils/JsonTransformer' | ||
import { Buffer } from '../../../utils/buffer' | ||
import { DidKey, KeyType } from '../domain/DidKey' | ||
|
||
import didKeyBls12381g2Fixture from './__fixtures__/didKeyBls12381g2.json' | ||
|
||
const TEST_BLS12381G2_BASE58_KEY = | ||
'mxE4sHTpbPcmxNviRVR9r7D2taXcNyVJmf9TBUFS1gRt3j3Ej9Seo59GQeCzYwbQgDrfWCwEJvmBwjLvheAky5N2NqFVzk4kuq3S8g4Fmekai4P622vHqWjFrsioYYDqhf9' | ||
const TEST_BLS12381G2_FINGERPRINT = | ||
'zUC71nmwvy83x1UzNKbZbS7N9QZx8rqpQx3Ee3jGfKiEkZngTKzsRoqobX6wZdZF5F93pSGYYco3gpK9tc53ruWUo2tkBB9bxPCFBUjq2th8FbtT4xih6y6Q1K9EL4Th86NiCGT' | ||
const TEST_BLS12381G2_DID = `did:key:${TEST_BLS12381G2_FINGERPRINT}` | ||
const TEST_BLS12381G2_KEY_ID = `${TEST_BLS12381G2_DID}#${TEST_BLS12381G2_FINGERPRINT}` | ||
const TEST_BLS12381G2_PREFIX_BYTES = Buffer.concat([ | ||
new Uint8Array([235, 1]), | ||
BufferEncoder.fromBase58(TEST_BLS12381G2_BASE58_KEY), | ||
]) | ||
|
||
describe('DidKey', () => { | ||
describe('bls12381g2', () => { | ||
it('creates a DidKey instance from public key bytes and bls12381g2 key type', async () => { | ||
const publicKeyBytes = BufferEncoder.fromBase58(TEST_BLS12381G2_BASE58_KEY) | ||
|
||
const didKey = DidKey.fromPublicKey(publicKeyBytes, KeyType.BLS12381G2) | ||
|
||
expect(didKey.did).toBe(TEST_BLS12381G2_DID) | ||
}) | ||
|
||
it('creates a DidKey instance from a base58 encoded public key and bls12381g2 key type', async () => { | ||
const didKey = DidKey.fromPublicKeyBase58(TEST_BLS12381G2_BASE58_KEY, KeyType.BLS12381G2) | ||
|
||
expect(didKey.did).toBe(TEST_BLS12381G2_DID) | ||
}) | ||
|
||
it('creates a DidKey instance from a fingerprint', async () => { | ||
const didKey = DidKey.fromFingerprint(TEST_BLS12381G2_FINGERPRINT) | ||
|
||
expect(didKey.did).toBe(TEST_BLS12381G2_DID) | ||
}) | ||
|
||
it('creates a DidKey instance from a did', async () => { | ||
const didKey = DidKey.fromDid(TEST_BLS12381G2_DID) | ||
|
||
expect(didKey.publicKeyBase58).toBe(TEST_BLS12381G2_BASE58_KEY) | ||
}) | ||
|
||
it('should correctly calculate the getter properties', async () => { | ||
const didKey = DidKey.fromDid(TEST_BLS12381G2_DID) | ||
|
||
expect(didKey.fingerprint).toBe(TEST_BLS12381G2_FINGERPRINT) | ||
expect(didKey.did).toBe(TEST_BLS12381G2_DID) | ||
expect(didKey.publicKeyBase58).toBe(TEST_BLS12381G2_BASE58_KEY) | ||
expect(didKey.publicKey).toEqual(BufferEncoder.fromBase58(TEST_BLS12381G2_BASE58_KEY)) | ||
expect(didKey.keyType).toBe(KeyType.BLS12381G2) | ||
expect(didKey.keyId).toBe(TEST_BLS12381G2_KEY_ID) | ||
expect(didKey.prefixedPublicKey.equals(TEST_BLS12381G2_PREFIX_BYTES)).toBe(true) | ||
}) | ||
|
||
it('should return a valid did:key did document for the did', async () => { | ||
const didKey = DidKey.fromDid(TEST_BLS12381G2_DID) | ||
|
||
expect(JsonTransformer.toJSON(didKey.didDocument)).toMatchObject(didKeyBls12381g2Fixture) | ||
}) | ||
}) | ||
}) |
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.
Are we sure that those deps will work with React Native?
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.
I know of other react native wallets using the did-resolver library, so pretty sure this will work!
I'll make sure to do a test run to be sure!