Skip to content

Commit

Permalink
refactor(wallet)!: remove wallet.createDid method (openwallet-foundat…
Browse files Browse the repository at this point in the history
…ion#1180)

* chore: deprecate agent public did
  • Loading branch information
TimoGlastra authored Dec 22, 2022
1 parent a0b6602 commit 5a6e40a
Show file tree
Hide file tree
Showing 23 changed files with 144 additions and 106 deletions.
3 changes: 1 addition & 2 deletions packages/bbs-signatures/tests/bbs-signatures.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
KeyType,
JsonTransformer,
DidKey,
Key,
SigningProviderRegistry,
W3cVerifiableCredential,
W3cCredentialService,
Expand Down Expand Up @@ -220,7 +219,7 @@ describeSkipNode17And18('BBS W3cCredentialService', () => {

describe('signPresentation', () => {
it('should sign the presentation successfully', async () => {
const signingKey = Key.fromPublicKeyBase58((await wallet.createDid({ seed })).verkey, KeyType.Ed25519)
const signingKey = await wallet.createKey({ seed, keyType: KeyType.Ed25519 })
const signingDidKey = new DidKey(signingKey)
const verificationMethod = `${signingDidKey.did}#${signingDidKey.key.fingerprint}`
const presentation = JsonTransformer.fromJSON(BbsBlsSignature2020Fixtures.TEST_VP_DOCUMENT, W3cPresentation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { describeSkipNode17And18 } from './util'

// use raw key derivation method to speed up wallet creating / opening / closing between tests
const walletConfig: WalletConfig = {
id: 'Wallet: IndyWalletTest',
id: 'Wallet: BBS Signing Provider',
// generated using indy.generateWalletKey
key: 'CwNJroKHTSSj3XvE7ZAnuKiTn2C4QkFvxEqfm5rzhNrb',
keyDerivationMethod: KeyDerivationMethod.Raw,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describeSkipNode17And18('credentials, BBS+ signature', () => {
'Alice Agent Credentials LD BBS+'
))
wallet = faberAgent.injectionContainer.resolve<Wallet>(InjectionSymbols.Wallet)
await wallet.createDid({ seed })
await wallet.createKey({ keyType: KeyType.Ed25519, seed })
const key = await wallet.createKey({ keyType: KeyType.Bls12381g2, seed })

issuerDidKey = new DidKey(key)
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/agent/AgentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export class AgentConfig {
}

/**
* @todo remove once did registrar module is available
* @deprecated The public did functionality of the wallet has been deprecated in favour of the DidsModule, which can be
* used to create and resolve dids. Currently the global agent public did functionality is still used by the `LedgerModule`, but
* will be removed once the `LedgerModule` has been deprecated. Do not use this property for new functionality, but rather
* use the `DidsModule`.
*/
public get publicDidSeed() {
return this.initConfig.publicDidSeed
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/agent/BaseAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ export abstract class BaseAgent<AgentModules extends ModulesMap = EmptyModuleMap
}
}

/**
* @deprecated The publicDid property has been deprecated in favour of the DidsModule, which can be used to
* create and resolve dids. Currently the global agent `publicDid` property is still used by the `LedgerModule`, but
* will be removed once the LedgerApi has been refactored. Do not use this property for new functionality, but rather
* use the `DidsModule`.
*/
public get publicDid() {
return this.agentContext.wallet.publicDid
}
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/crypto/__tests__/JwsService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { DidKey } from '../../modules/dids'
import { Buffer, JsonEncoder } from '../../utils'
import { IndyWallet } from '../../wallet/IndyWallet'
import { JwsService } from '../JwsService'
import { Key } from '../Key'
import { KeyType } from '../KeyType'
import { SigningProviderRegistry } from '../signing-provider'

Expand Down Expand Up @@ -36,15 +35,15 @@ describe('JwsService', () => {

describe('createJws', () => {
it('creates a jws for the payload with the key associated with the verkey', async () => {
const { verkey } = await wallet.createDid({ seed: didJwsz6Mkf.SEED })
const key = await wallet.createKey({ seed: didJwsz6Mkf.SEED, keyType: KeyType.Ed25519 })

const payload = JsonEncoder.toBuffer(didJwsz6Mkf.DATA_JSON)
const key = Key.fromPublicKeyBase58(verkey, KeyType.Ed25519)
const kid = new DidKey(key).did

const jws = await jwsService.createJws(agentContext, {
payload,
verkey,
// FIXME: update to use key instance instead of verkey
verkey: key.publicKeyBase58,
header: { kid },
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getAgentConfig } from '../../../tests/helpers'
import { KeyType } from '../../crypto'
import { SigningProviderRegistry } from '../../crypto/signing-provider'
import { IndyWallet } from '../../wallet/IndyWallet'

Expand Down Expand Up @@ -53,9 +54,9 @@ describe('Decorators | Signature | SignatureDecoratorUtils', () => {

test('signData signs json object and returns SignatureDecorator', async () => {
const seed1 = '00000000000000000000000000000My1'
const { verkey } = await wallet.createDid({ seed: seed1 })
const key = await wallet.createKey({ seed: seed1, keyType: KeyType.Ed25519 })

const result = await signData(data, wallet, verkey)
const result = await signData(data, wallet, key.publicKeyBase58)

expect(result).toEqual(signedData)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Key, KeyType } from '../../../crypto'
import { SigningProviderRegistry } from '../../../crypto/signing-provider'
import { signData, unpackAndVerifySignatureDecorator } from '../../../decorators/signature/SignatureDecoratorUtils'
import { JsonTransformer } from '../../../utils/JsonTransformer'
import { indyDidFromPublicKeyBase58 } from '../../../utils/did'
import { uuid } from '../../../utils/uuid'
import { IndyWallet } from '../../../wallet/IndyWallet'
import { AckMessage, AckStatus } from '../../common'
Expand Down Expand Up @@ -388,8 +389,10 @@ describe('ConnectionService', () => {
it('returns a connection response message containing the information from the connection record', async () => {
expect.assertions(2)

const key = await wallet.createKey({ keyType: KeyType.Ed25519 })
const did = indyDidFromPublicKeyBase58(key.publicKeyBase58)

// Needed for signing connection~sig
const { did, verkey } = await wallet.createDid()
const mockConnection = getMockConnection({
state: DidExchangeState.RequestReceived,
role: DidExchangeRole.Responder,
Expand All @@ -398,13 +401,13 @@ describe('ConnectionService', () => {
},
})

const recipientKeys = [new DidKey(Key.fromPublicKeyBase58(verkey, KeyType.Ed25519))]
const recipientKeys = [new DidKey(key)]
const outOfBand = getMockOutOfBand({ recipientKeys: recipientKeys.map((did) => did.did) })

const publicKey = new Ed25119Sig2018({
id: `${did}#1`,
controller: did,
publicKeyBase58: verkey,
publicKeyBase58: key.publicKeyBase58,
})
const mockDidDoc = new DidDoc({
id: did,
Expand Down Expand Up @@ -477,17 +480,18 @@ describe('ConnectionService', () => {
it('returns a connection record containing the information from the connection response', async () => {
expect.assertions(2)

const { did, verkey } = await wallet.createDid()
const { did: theirDid, verkey: theirVerkey } = await wallet.createDid()
const key = await wallet.createKey({ keyType: KeyType.Ed25519 })
const did = indyDidFromPublicKeyBase58(key.publicKeyBase58)

const theirKey = await wallet.createKey({ keyType: KeyType.Ed25519 })
const theirDid = indyDidFromPublicKeyBase58(key.publicKeyBase58)

const connectionRecord = getMockConnection({
did,
state: DidExchangeState.RequestSent,
role: DidExchangeRole.Requester,
})

const theirKey = Key.fromPublicKeyBase58(theirVerkey, KeyType.Ed25519)

const otherPartyConnection = new Connection({
did: theirDid,
didDoc: new DidDoc({
Expand All @@ -513,7 +517,7 @@ describe('ConnectionService', () => {
})

const plainConnection = JsonTransformer.toJSON(otherPartyConnection)
const connectionSig = await signData(plainConnection, wallet, theirVerkey)
const connectionSig = await signData(plainConnection, wallet, theirKey.publicKeyBase58)

const connectionResponse = new ConnectionResponseMessage({
threadId: uuid(),
Expand All @@ -527,7 +531,7 @@ describe('ConnectionService', () => {
agentContext,
connection: connectionRecord,
senderKey: theirKey,
recipientKey: Key.fromPublicKeyBase58(verkey, KeyType.Ed25519),
recipientKey: key,
})

const processedConnection = await connectionService.processResponse(messageContext, outOfBandRecord)
Expand Down Expand Up @@ -562,16 +566,17 @@ describe('ConnectionService', () => {
it('throws an error when the connection sig is not signed with the same key as the recipient key from the invitation', async () => {
expect.assertions(1)

const { did, verkey } = await wallet.createDid()
const { did: theirDid, verkey: theirVerkey } = await wallet.createDid()
const key = await wallet.createKey({ keyType: KeyType.Ed25519 })
const did = indyDidFromPublicKeyBase58(key.publicKeyBase58)

const theirKey = await wallet.createKey({ keyType: KeyType.Ed25519 })
const theirDid = indyDidFromPublicKeyBase58(key.publicKeyBase58)
const connectionRecord = getMockConnection({
did,
role: DidExchangeRole.Requester,
state: DidExchangeState.RequestSent,
})

const theirKey = Key.fromPublicKeyBase58(theirVerkey, KeyType.Ed25519)

const otherPartyConnection = new Connection({
did: theirDid,
didDoc: new DidDoc({
Expand All @@ -596,7 +601,7 @@ describe('ConnectionService', () => {
}),
})
const plainConnection = JsonTransformer.toJSON(otherPartyConnection)
const connectionSig = await signData(plainConnection, wallet, theirVerkey)
const connectionSig = await signData(plainConnection, wallet, theirKey.publicKeyBase58)

const connectionResponse = new ConnectionResponseMessage({
threadId: uuid(),
Expand All @@ -606,13 +611,13 @@ describe('ConnectionService', () => {
// Recipient key `verkey` is not the same as theirVerkey which was used to sign message,
// therefore it should cause a failure.
const outOfBandRecord = getMockOutOfBand({
recipientKeys: [new DidKey(Key.fromPublicKeyBase58(verkey, KeyType.Ed25519)).did],
recipientKeys: [new DidKey(key).did],
})
const messageContext = new InboundMessageContext(connectionResponse, {
agentContext,
connection: connectionRecord,
senderKey: theirKey,
recipientKey: Key.fromPublicKeyBase58(verkey, KeyType.Ed25519),
recipientKey: key,
})

return expect(connectionService.processResponse(messageContext, outOfBandRecord)).rejects.toThrowError(
Expand All @@ -625,19 +630,20 @@ describe('ConnectionService', () => {
it('throws an error when the message does not contain a DID Document', async () => {
expect.assertions(1)

const { did } = await wallet.createDid()
const { did: theirDid, verkey: theirVerkey } = await wallet.createDid()
const key = await wallet.createKey({ keyType: KeyType.Ed25519 })
const did = indyDidFromPublicKeyBase58(key.publicKeyBase58)

const theirKey = await wallet.createKey({ keyType: KeyType.Ed25519 })
const theirDid = indyDidFromPublicKeyBase58(key.publicKeyBase58)
const connectionRecord = getMockConnection({
did,
state: DidExchangeState.RequestSent,
theirDid: undefined,
})

const theirKey = Key.fromPublicKeyBase58(theirVerkey, KeyType.Ed25519)

const otherPartyConnection = new Connection({ did: theirDid })
const plainConnection = JsonTransformer.toJSON(otherPartyConnection)
const connectionSig = await signData(plainConnection, wallet, theirVerkey)
const connectionSig = await signData(plainConnection, wallet, theirKey.publicKeyBase58)

const connectionResponse = new ConnectionResponseMessage({ threadId: uuid(), connectionSig })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import type {
import type { IndyCredentialFormat } from './IndyCredentialFormat'
import type * as Indy from 'indy-sdk'

import { KeyType } from '../../../../crypto'
import { Attachment, AttachmentData } from '../../../../decorators/attachment/Attachment'
import { AriesFrameworkError } from '../../../../error'
import { JsonEncoder } from '../../../../utils/JsonEncoder'
import { JsonTransformer } from '../../../../utils/JsonTransformer'
import { MessageValidator } from '../../../../utils/MessageValidator'
import { TypedArrayEncoder } from '../../../../utils/TypedArrayEncoder'
import { getIndyDidFromVerificationMethod } from '../../../../utils/did'
import { uuid } from '../../../../utils/uuid'
import { ConnectionService } from '../../../connections'
Expand Down Expand Up @@ -517,7 +519,8 @@ export class IndyCredentialFormatService implements CredentialFormatService<Indy
// If it wasn't successful to extract the did from the connection, we'll create a new key (e.g. if using connection-less)
// FIXME: we already create a did for the exchange when using connection-less, but this is on a higher level. We should look at
// a way to reuse this key, but for now this is easier.
const { did } = await agentContext.wallet.createDid()
const key = await agentContext.wallet.createKey({ keyType: KeyType.Ed25519 })
const did = TypedArrayEncoder.toBase58(key.publicKey.slice(0, 16))

return did
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getAgentOptions, prepareForIssuance, waitForCredentialRecordSubject } f
import testLogger from '../../../../../../tests/logger'
import { Agent } from '../../../../../agent/Agent'
import { InjectionSymbols } from '../../../../../constants'
import { KeyType } from '../../../../../crypto'
import { JsonEncoder } from '../../../../../utils/JsonEncoder'
import { W3cVcModule } from '../../../../vc'
import { customDocumentLoader } from '../../../../vc/__tests__/documentLoader'
Expand Down Expand Up @@ -104,7 +105,8 @@ describe('credentials', () => {
.observable<CredentialStateChangedEvent>(CredentialEventTypes.CredentialStateChanged)
.subscribe(aliceReplay)
wallet = faberAgent.injectionContainer.resolve<Wallet>(InjectionSymbols.Wallet)
await wallet.createDid({ seed })

await wallet.createKey({ seed, keyType: KeyType.Ed25519 })

signCredentialOptions = {
credential: TEST_LD_DOCUMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { JsonCredential, JsonLdCredentialDetailFormat } from '../../../form
import { setupCredentialTests, waitForCredentialRecord } from '../../../../../../tests/helpers'
import testLogger from '../../../../../../tests/logger'
import { InjectionSymbols } from '../../../../../constants'
import { KeyType } from '../../../../../crypto'
import { AriesFrameworkError } from '../../../../../error/AriesFrameworkError'
import { CREDENTIALS_CONTEXT_V1_URL } from '../../../../vc/constants'
import { AutoAcceptCredential, CredentialState } from '../../../models'
Expand Down Expand Up @@ -43,7 +44,7 @@ describe('credentials', () => {
))

wallet = faberAgent.injectionContainer.resolve<Wallet>(InjectionSymbols.Wallet)
await wallet.createDid({ seed })
await wallet.createKey({ seed, keyType: KeyType.Ed25519 })
signCredentialOptions = {
credential: TEST_LD_DOCUMENT,
options: {
Expand Down Expand Up @@ -142,7 +143,7 @@ describe('credentials', () => {
AutoAcceptCredential.ContentApproved
))
wallet = faberAgent.injectionContainer.resolve<Wallet>(InjectionSymbols.Wallet)
await wallet.createDid({ seed })
await wallet.createKey({ seed, keyType: KeyType.Ed25519 })
signCredentialOptions = {
credential: TEST_LD_DOCUMENT,
options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { JsonCredential, JsonLdCredentialDetailFormat } from '../../../form
import { setupCredentialTests, waitForCredentialRecord } from '../../../../../../tests/helpers'
import testLogger from '../../../../../../tests/logger'
import { InjectionSymbols } from '../../../../../constants'
import { KeyType } from '../../../../../crypto'
import { DidCommMessageRepository } from '../../../../../storage'
import { JsonTransformer } from '../../../../../utils/JsonTransformer'
import { CredentialState } from '../../../models'
Expand Down Expand Up @@ -65,7 +66,7 @@ describe('credentials', () => {
'Alice Agent Credentials LD'
))
wallet = faberAgent.injectionContainer.resolve<Wallet>(InjectionSymbols.Wallet)
await wallet.createDid({ seed })
await wallet.createKey({ seed, keyType: KeyType.Ed25519 })
signCredentialOptions = {
credential: inputDocAsJson,
options: {
Expand Down
Loading

0 comments on commit 5a6e40a

Please sign in to comment.