Skip to content

Commit

Permalink
Merge branch 'main' into feat/implicit-invitations
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
  • Loading branch information
genaris authored Mar 2, 2023
2 parents 9a9f581 + 18abb18 commit 440914e
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 28 deletions.
3 changes: 1 addition & 2 deletions packages/core/src/agent/MessageSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ReturnRouteTypes } from '../decorators/transport/TransportDecorator'
import { AriesFrameworkError, MessageSendingError } from '../error'
import { Logger } from '../logger'
import { DidCommDocumentService } from '../modules/didcomm'
import { getKeyDidMappingByVerificationMethod } from '../modules/dids/domain/key-type'
import { getKeyFromVerificationMethod } from '../modules/dids/domain/key-type'
import { didKeyToInstanceOfKey } from '../modules/dids/helpers'
import { DidResolverService } from '../modules/dids/services/DidResolverService'
import { inject, injectable } from '../plugins'
Expand Down Expand Up @@ -508,7 +508,6 @@ function getAuthenticationKeys(didDocument: DidDocument) {
didDocument.authentication?.map((authentication) => {
const verificationMethod =
typeof authentication === 'string' ? didDocument.dereferenceVerificationMethod(authentication) : authentication
const { getKeyFromVerificationMethod } = getKeyDidMappingByVerificationMethod(verificationMethod)
const key = getKeyFromVerificationMethod(verificationMethod)
return key
}) ?? []
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/crypto/WalletKeyPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LdKeyPairOptions } from '../modules/vc/models/LdKeyPair'
import type { Wallet } from '../wallet'

import { VerificationMethod } from '../modules/dids'
import { getKeyDidMappingByVerificationMethod } from '../modules/dids/domain/key-type/keyDidMapping'
import { getKeyFromVerificationMethod } from '../modules/dids/domain/key-type/keyDidMapping'
import { LdKeyPair } from '../modules/vc/models/LdKeyPair'
import { JsonTransformer } from '../utils'
import { MessageValidator } from '../utils/MessageValidator'
Expand Down Expand Up @@ -43,7 +43,6 @@ export function createWalletKeyPairClass(wallet: Wallet) {
public static async from(verificationMethod: VerificationMethod): Promise<WalletKeyPair> {
const vMethod = JsonTransformer.fromJSON(verificationMethod, VerificationMethod)
MessageValidator.validateSync(vMethod)
const { getKeyFromVerificationMethod } = getKeyDidMappingByVerificationMethod(vMethod)
const key = getKeyFromVerificationMethod(vMethod)

return new WalletKeyPair({
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/modules/connections/DidExchangeProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
getNumAlgoFromPeerDid,
PeerDidNumAlgo,
} from '../dids'
import { getKeyDidMappingByVerificationMethod } from '../dids/domain/key-type'
import { getKeyFromVerificationMethod } from '../dids/domain/key-type'
import { tryParseDid } from '../dids/domain/parse'
import { didKeyToInstanceOfKey } from '../dids/helpers'
import { DidRecord, DidRepository } from '../dids/repository'
Expand Down Expand Up @@ -528,7 +528,6 @@ export class DidExchangeProtocol {
typeof authentication === 'string'
? didDocument.dereferenceVerificationMethod(authentication)
: authentication
const { getKeyFromVerificationMethod } = getKeyDidMappingByVerificationMethod(verificationMethod)
const key = getKeyFromVerificationMethod(verificationMethod)
return key.publicKeyBase58
})
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/modules/dids/domain/DidDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { KeyType, Key } from '../../../crypto'
import { JsonTransformer } from '../../../utils/JsonTransformer'
import { IsStringOrStringArray } from '../../../utils/transformers'

import { getKeyDidMappingByVerificationMethod } from './key-type'
import { getKeyFromVerificationMethod } from './key-type'
import { IndyAgentService, ServiceTransformer, DidCommV1Service } from './service'
import { VerificationMethodTransformer, VerificationMethod, IsStringOrVerificationMethod } from './verificationMethod'

Expand Down Expand Up @@ -210,7 +210,6 @@ export function keyReferenceToKey(didDocument: DidDocument, keyId: string) {
// for didcomm. In the future we should update this to only be allowed for IndyAgent and DidCommV1 services
// as didcomm v2 doesn't have this issue anymore
const verificationMethod = didDocument.dereferenceKey(keyId, ['authentication', 'keyAgreement'])
const { getKeyFromVerificationMethod } = getKeyDidMappingByVerificationMethod(verificationMethod)
const key = getKeyFromVerificationMethod(verificationMethod)

return key
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/dids/domain/key-type/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { getKeyDidMappingByKeyType, getKeyDidMappingByVerificationMethod } from './keyDidMapping'
export { getKeyDidMappingByKeyType, getKeyFromVerificationMethod } from './keyDidMapping'

export * from './bls12381g2'
export * from './bls12381g1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ export function getKeyDidMappingByKeyType(keyType: KeyType) {
return keyDid
}

export function getKeyDidMappingByVerificationMethod(verificationMethod: VerificationMethod) {
export function getKeyFromVerificationMethod(verificationMethod: VerificationMethod) {
const keyDid = verificationMethodKeyDidMapping[verificationMethod.type]

if (!keyDid) {
throw new Error(`Unsupported key did from verification method type '${verificationMethod.type}'`)
}

return keyDid
return keyDid.getKeyFromVerificationMethod(verificationMethod)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Key } from '../../../../crypto'
import { JsonEncoder, JsonTransformer } from '../../../../utils'
import { DidCommV1Service, DidDocumentService } from '../../domain'
import { DidDocumentBuilder } from '../../domain/DidDocumentBuilder'
import { getKeyDidMappingByKeyType, getKeyDidMappingByVerificationMethod } from '../../domain/key-type'
import { getKeyFromVerificationMethod, getKeyDidMappingByKeyType } from '../../domain/key-type'
import { parseDid } from '../../domain/parse'
import { DidKey } from '../key'

Expand Down Expand Up @@ -116,7 +116,6 @@ export function didDocumentToNumAlgo2Did(didDocument: DidDocument) {

// Transform als verification methods into a fingerprint (multibase, multicodec)
const encoded = dereferenced.map((entry) => {
const { getKeyFromVerificationMethod } = getKeyDidMappingByVerificationMethod(entry)
const key = getKeyFromVerificationMethod(entry)

// Encode as '.PurposeFingerprint'
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/modules/vc/W3cCredentialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AriesFrameworkError } from '../../error'
import { injectable } from '../../plugins'
import { JsonTransformer } from '../../utils'
import { VerificationMethod } from '../dids'
import { getKeyDidMappingByVerificationMethod } from '../dids/domain/key-type'
import { getKeyFromVerificationMethod } from '../dids/domain/key-type'

import { SignatureSuiteRegistry } from './SignatureSuiteRegistry'
import { W3cVcModuleConfig } from './W3cVcModuleConfig'
Expand Down Expand Up @@ -297,9 +297,8 @@ export class W3cCredentialService {
const verificationMethodObject = await documentLoader(verificationMethod)
const verificationMethodClass = JsonTransformer.fromJSON(verificationMethodObject.document, VerificationMethod)

const key = getKeyDidMappingByVerificationMethod(verificationMethodClass)

return key.getKeyFromVerificationMethod(verificationMethodClass)
const key = getKeyFromVerificationMethod(verificationMethodClass)
return key
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transport/WsOutboundTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class WsOutboundTransport implements OutboundTransport {
throw new AriesFrameworkError("Missing connection or endpoint. I don't know how and where to send the message.")
}

const isNewSocket = this.hasOpenSocket(endpoint)
const isNewSocket = !this.hasOpenSocket(endpoint)
const socket = await this.resolveSocket({ socketId: endpoint, endpoint, connectionId })

socket.send(Buffer.from(JSON.stringify(payload)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
import type { AgentContext } from '@aries-framework/core'
import type { Schema as IndySdkSchema } from 'indy-sdk'

import { DidsApi, getKeyDidMappingByVerificationMethod } from '@aries-framework/core'
import { DidsApi, getKeyFromVerificationMethod } from '@aries-framework/core'

import { IndySdkError, isIndyError } from '../../error'
import { IndySdkPoolService } from '../../ledger'
Expand Down Expand Up @@ -159,7 +159,6 @@ export class IndySdkAnonCredsRegistry implements AnonCredsRegistry {
}

const verificationMethod = didResult.didDocument.dereferenceKey(`did:sov:${options.schema.issuerId}#key-1`)
const { getKeyFromVerificationMethod } = getKeyDidMappingByVerificationMethod(verificationMethod)
const submitterKey = getKeyFromVerificationMethod(verificationMethod)

const response = await indySdkPoolService.submitWriteRequest(agentContext, pool, request, submitterKey)
Expand Down Expand Up @@ -373,7 +372,6 @@ export class IndySdkAnonCredsRegistry implements AnonCredsRegistry {
const verificationMethod = didResult.didDocument.dereferenceKey(
`did:sov:${options.credentialDefinition.issuerId}#key-1`
)
const { getKeyFromVerificationMethod } = getKeyDidMappingByVerificationMethod(verificationMethod)
const submitterKey = getKeyFromVerificationMethod(verificationMethod)

const response = await indySdkPoolService.submitWriteRequest(agentContext, pool, request, submitterKey)
Expand Down
3 changes: 1 addition & 2 deletions packages/indy-sdk/src/dids/IndySdkSovDidRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import type { NymRole } from 'indy-sdk'

import {
DidsApi,
getKeyDidMappingByVerificationMethod,
KeyType,
isValidPrivateKey,
DidDocumentRole,
DidRecord,
DidRepository,
getKeyFromVerificationMethod,
} from '@aries-framework/core'

import { IndySdkError } from '../error'
Expand Down Expand Up @@ -89,7 +89,6 @@ export class IndySdkSovDidRegistrar implements DidRegistrar {
}

const verificationMethod = didResult.didDocument.dereferenceKey(submitterVerificationMethod)
const { getKeyFromVerificationMethod } = getKeyDidMappingByVerificationMethod(verificationMethod)
const submitterSigningKey = getKeyFromVerificationMethod(verificationMethod)

const qualifiedSovDid = `did:sov:${unqualifiedIndyDid}`
Expand Down
4 changes: 1 addition & 3 deletions packages/indy-vdr/src/anoncreds/IndyVdrAnonCredsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
} from '@aries-framework/anoncreds'
import type { AgentContext } from '@aries-framework/core'

import { DidsApi, getKeyDidMappingByVerificationMethod } from '@aries-framework/core'
import { getKeyFromVerificationMethod, DidsApi } from '@aries-framework/core'
import {
GetSchemaRequest,
SchemaRequest,
Expand Down Expand Up @@ -154,7 +154,6 @@ export class IndyVdrAnonCredsRegistry implements AnonCredsRegistry {
}

const verificationMethod = didResult.didDocument.dereferenceKey(`did:sov:${options.schema.issuerId}#key-1`)
const { getKeyFromVerificationMethod } = getKeyDidMappingByVerificationMethod(verificationMethod)
const key = getKeyFromVerificationMethod(verificationMethod)

const response = await pool.submitWriteRequest(agentContext, schemaRequest, key)
Expand Down Expand Up @@ -348,7 +347,6 @@ export class IndyVdrAnonCredsRegistry implements AnonCredsRegistry {
const verificationMethod = didResult.didDocument.dereferenceKey(
`did:sov:${options.credentialDefinition.issuerId}#key-1`
)
const { getKeyFromVerificationMethod } = getKeyDidMappingByVerificationMethod(verificationMethod)
const key = getKeyFromVerificationMethod(verificationMethod)

const response = await pool.submitWriteRequest(agentContext, credentialDefinitionRequest, key)
Expand Down
3 changes: 1 addition & 2 deletions packages/openid4vc-client/src/OpenId4VcClientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import type { AgentContext, W3cCredentialRecord } from '@aries-framework/core'
import type { EndpointMetadata, Jwt } from '@sphereon/openid4vci-client'

import {
getKeyFromVerificationMethod,
inject,
InjectionSymbols,
isJwtAlgorithm,
Logger,
DidsApi,
getKeyDidMappingByVerificationMethod,
AriesFrameworkError,
injectable,
JsonEncoder,
Expand Down Expand Up @@ -85,7 +85,6 @@ export class OpenId4VcClientService {

// TODO: which purposes are allowed?
const verificationMethod = didResult.didDocument.dereferenceKey(kid, ['authentication'])
const { getKeyFromVerificationMethod } = getKeyDidMappingByVerificationMethod(verificationMethod)
const key = getKeyFromVerificationMethod(verificationMethod)

const payload = JsonEncoder.toBuffer(jwt.payload)
Expand Down

0 comments on commit 440914e

Please sign in to comment.