@credo-ts/indy-vdr 0.6.1-pr-2091-20241119140918 → 0.6.2-alpha-20251210145840
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/IndyVdrApi.d.mts +42 -0
- package/build/IndyVdrApi.d.mts.map +1 -0
- package/build/IndyVdrApi.mjs +72 -0
- package/build/IndyVdrApi.mjs.map +1 -0
- package/build/IndyVdrModule.d.mts +20 -0
- package/build/IndyVdrModule.d.mts.map +1 -0
- package/build/IndyVdrModule.mjs +30 -0
- package/build/IndyVdrModule.mjs.map +1 -0
- package/build/IndyVdrModuleConfig.d.mts +72 -0
- package/build/IndyVdrModuleConfig.d.mts.map +1 -0
- package/build/IndyVdrModuleConfig.mjs +18 -0
- package/build/IndyVdrModuleConfig.mjs.map +1 -0
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs +10 -0
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs +7 -0
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateParam.mjs +9 -0
- package/build/anoncreds/IndyVdrAnonCredsRegistry.d.mts +125 -0
- package/build/anoncreds/IndyVdrAnonCredsRegistry.d.mts.map +1 -0
- package/build/anoncreds/IndyVdrAnonCredsRegistry.mjs +586 -0
- package/build/anoncreds/IndyVdrAnonCredsRegistry.mjs.map +1 -0
- package/build/anoncreds/index.d.mts +1 -0
- package/build/anoncreds/index.mjs +1 -0
- package/build/anoncreds/utils/identifiers.mjs +29 -0
- package/build/anoncreds/utils/identifiers.mjs.map +1 -0
- package/build/anoncreds/utils/transform.mjs +63 -0
- package/build/anoncreds/utils/transform.mjs.map +1 -0
- package/build/dids/IndyVdrIndyDidRegistrar.d.mts +92 -0
- package/build/dids/IndyVdrIndyDidRegistrar.d.mts.map +1 -0
- package/build/dids/IndyVdrIndyDidRegistrar.mjs +290 -0
- package/build/dids/IndyVdrIndyDidRegistrar.mjs.map +1 -0
- package/build/dids/IndyVdrIndyDidResolver.d.mts +12 -0
- package/build/dids/IndyVdrIndyDidResolver.d.mts.map +1 -0
- package/build/dids/IndyVdrIndyDidResolver.mjs +36 -0
- package/build/dids/IndyVdrIndyDidResolver.mjs.map +1 -0
- package/build/dids/IndyVdrSovDidResolver.d.mts +13 -0
- package/build/dids/IndyVdrSovDidResolver.d.mts.map +1 -0
- package/build/dids/IndyVdrSovDidResolver.mjs +70 -0
- package/build/dids/IndyVdrSovDidResolver.mjs.map +1 -0
- package/build/dids/didIndyUtil.mjs +147 -0
- package/build/dids/didIndyUtil.mjs.map +1 -0
- package/build/dids/didSovUtil.mjs +118 -0
- package/build/dids/didSovUtil.mjs.map +1 -0
- package/build/dids/index.d.mts +3 -0
- package/build/dids/index.mjs +3 -0
- package/build/error/IndyVdrError.mjs +12 -0
- package/build/error/IndyVdrError.mjs.map +1 -0
- package/build/error/IndyVdrNotConfiguredError.mjs +12 -0
- package/build/error/IndyVdrNotConfiguredError.mjs.map +1 -0
- package/build/error/IndyVdrNotFound.mjs +12 -0
- package/build/error/IndyVdrNotFound.mjs.map +1 -0
- package/build/error/index.mjs +3 -0
- package/build/index.d.mts +12 -0
- package/build/index.mjs +12 -0
- package/build/pool/IndyVdrPool.d.mts +61 -0
- package/build/pool/IndyVdrPool.d.mts.map +1 -0
- package/build/pool/IndyVdrPool.mjs +104 -0
- package/build/pool/IndyVdrPool.mjs.map +1 -0
- package/build/pool/IndyVdrPoolService.d.mts +54 -0
- package/build/pool/IndyVdrPoolService.d.mts.map +1 -0
- package/build/pool/IndyVdrPoolService.mjs +157 -0
- package/build/pool/IndyVdrPoolService.mjs.map +1 -0
- package/build/pool/index.d.mts +2 -0
- package/build/pool/index.mjs +2 -0
- package/build/utils/did.mjs +48 -0
- package/build/utils/did.mjs.map +1 -0
- package/build/utils/promises.mjs +20 -0
- package/build/utils/promises.mjs.map +1 -0
- package/build/utils/sign.mjs +24 -0
- package/build/utils/sign.mjs.map +1 -0
- package/package.json +19 -19
- package/build/IndyVdrApi.d.ts +0 -34
- package/build/IndyVdrApi.js +0 -82
- package/build/IndyVdrApi.js.map +0 -1
- package/build/IndyVdrModule.d.ts +0 -14
- package/build/IndyVdrModule.js +0 -31
- package/build/IndyVdrModule.js.map +0 -1
- package/build/IndyVdrModuleConfig.d.ts +0 -66
- package/build/IndyVdrModuleConfig.js +0 -18
- package/build/IndyVdrModuleConfig.js.map +0 -1
- package/build/anoncreds/IndyVdrAnonCredsRegistry.d.ts +0 -113
- package/build/anoncreds/IndyVdrAnonCredsRegistry.js +0 -682
- package/build/anoncreds/IndyVdrAnonCredsRegistry.js.map +0 -1
- package/build/anoncreds/index.d.ts +0 -1
- package/build/anoncreds/index.js +0 -18
- package/build/anoncreds/index.js.map +0 -1
- package/build/anoncreds/utils/identifiers.d.ts +0 -5
- package/build/anoncreds/utils/identifiers.js +0 -40
- package/build/anoncreds/utils/identifiers.js.map +0 -1
- package/build/anoncreds/utils/transform.d.ts +0 -32
- package/build/anoncreds/utils/transform.js +0 -91
- package/build/anoncreds/utils/transform.js.map +0 -1
- package/build/dids/IndyVdrIndyDidRegistrar.d.ts +0 -85
- package/build/dids/IndyVdrIndyDidRegistrar.js +0 -338
- package/build/dids/IndyVdrIndyDidRegistrar.js.map +0 -1
- package/build/dids/IndyVdrIndyDidResolver.d.ts +0 -7
- package/build/dids/IndyVdrIndyDidResolver.js +0 -39
- package/build/dids/IndyVdrIndyDidResolver.js.map +0 -1
- package/build/dids/IndyVdrSovDidResolver.d.ts +0 -8
- package/build/dids/IndyVdrSovDidResolver.js +0 -79
- package/build/dids/IndyVdrSovDidResolver.js.map +0 -1
- package/build/dids/didIndyUtil.d.ts +0 -47
- package/build/dids/didIndyUtil.js +0 -241
- package/build/dids/didIndyUtil.js.map +0 -1
- package/build/dids/didSovUtil.d.ts +0 -26
- package/build/dids/didSovUtil.js +0 -180
- package/build/dids/didSovUtil.js.map +0 -1
- package/build/dids/index.d.ts +0 -3
- package/build/dids/index.js +0 -10
- package/build/dids/index.js.map +0 -1
- package/build/error/IndyVdrError.d.ts +0 -6
- package/build/error/IndyVdrError.js +0 -11
- package/build/error/IndyVdrError.js.map +0 -1
- package/build/error/IndyVdrNotConfiguredError.d.ts +0 -6
- package/build/error/IndyVdrNotConfiguredError.js +0 -11
- package/build/error/IndyVdrNotConfiguredError.js.map +0 -1
- package/build/error/IndyVdrNotFound.d.ts +0 -6
- package/build/error/IndyVdrNotFound.js +0 -11
- package/build/error/IndyVdrNotFound.js.map +0 -1
- package/build/error/index.d.ts +0 -3
- package/build/error/index.js +0 -20
- package/build/error/index.js.map +0 -1
- package/build/index.d.ts +0 -5
- package/build/index.js +0 -27
- package/build/index.js.map +0 -1
- package/build/pool/IndyVdrPool.d.ts +0 -54
- package/build/pool/IndyVdrPool.js +0 -131
- package/build/pool/IndyVdrPool.js.map +0 -1
- package/build/pool/IndyVdrPoolService.d.ts +0 -55
- package/build/pool/IndyVdrPoolService.js +0 -175
- package/build/pool/IndyVdrPoolService.js.map +0 -1
- package/build/pool/index.d.ts +0 -2
- package/build/pool/index.js +0 -19
- package/build/pool/index.js.map +0 -1
- package/build/utils/did.d.ts +0 -32
- package/build/utils/did.js +0 -57
- package/build/utils/did.js.map +0 -1
- package/build/utils/promises.d.ts +0 -11
- package/build/utils/promises.js +0 -26
- package/build/utils/promises.js.map +0 -1
- package/build/utils/sign.d.ts +0 -5
- package/build/utils/sign.js +0 -23
- package/build/utils/sign.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"didIndyUtil.mjs","names":["output: Record<string, unknown>","key","diddocContent: Record<string, unknown>"],"sources":["../../src/dids/didIndyUtil.ts"],"sourcesContent":["import { parseIndyDid } from '@credo-ts/anoncreds'\nimport type { AgentContext } from '@credo-ts/core'\nimport {\n CredoError,\n convertPublicKeyToX25519,\n DidDocument,\n DidDocumentBuilder,\n DidsApi,\n getPublicJwkFromVerificationMethod,\n Hasher,\n JsonTransformer,\n Kms,\n TypedArrayEncoder,\n} from '@credo-ts/core'\nimport { GetAttribRequest, GetNymRequest } from '@hyperledger/indy-vdr-shared'\nimport { IndyVdrError, IndyVdrNotFoundError } from '../error'\nimport type { IndyVdrPool } from '../pool'\nimport type { GetNymResponseData, IndyEndpointAttrib } from './didSovUtil'\n\nimport { addServicesFromEndpointsAttrib, getFullVerkey } from './didSovUtil'\n\n// Create a base DIDDoc template according to https://hyperledger.github.io/indy-did-method/#base-diddoc-template\nexport function indyDidDocumentFromDid(did: string, verKeyBase58: string) {\n const verificationMethodId = `${did}#verkey`\n\n const publicKeyBase58 = verKeyBase58\n\n const builder = new DidDocumentBuilder(did)\n .addContext('https://w3id.org/security/suites/ed25519-2018/v1')\n .addVerificationMethod({\n controller: did,\n id: verificationMethodId,\n publicKeyBase58,\n type: 'Ed25519VerificationKey2018',\n })\n .addAuthentication(verificationMethodId)\n\n return builder\n}\n\nexport function createKeyAgreementKey(verkey: string) {\n return TypedArrayEncoder.toBase58(convertPublicKeyToX25519(TypedArrayEncoder.fromBase58(verkey)))\n}\n\nconst deepMerge = (a: Record<string, unknown>, b: Record<string, unknown>) => {\n const output: Record<string, unknown> = {}\n\n for (const key of [...new Set([...Object.keys(a), ...Object.keys(b)])]) {\n // Only an object includes a given key: just output it\n if (a[key] && !b[key]) {\n output[key] = a[key]\n } else if (!a[key] && b[key]) {\n output[key] = b[key]\n } else {\n // Both objects do include the key\n // Some or both are arrays\n if (Array.isArray(a[key])) {\n if (Array.isArray(b[key])) {\n const element = new Set()\n\n for (const item of a[key] as Array<unknown>) {\n element.add(item)\n }\n\n for (const item of b[key] as Array<unknown>) {\n element.add(item)\n }\n\n output[key] = Array.from(element)\n } else {\n // biome-ignore lint/suspicious/noExplicitAny: no explanation\n const arr = a[key] as Array<any>\n output[key] = Array.from(new Set(...arr, b[key]))\n }\n } else if (Array.isArray(b[key])) {\n // biome-ignore lint/suspicious/noExplicitAny: no explanation\n const arr = b[key] as Array<any>\n output[key] = Array.from(new Set(...arr, a[key]))\n // Both elements are objects: recursive merge\n } else if (typeof a[key] === 'object' && typeof b[key] === 'object') {\n output[key] = deepMerge(a, b)\n }\n }\n }\n return output\n}\n\n/**\n * Combine a JSON content with the contents of a DidDocument\n * @param didDoc object containing original DIDDocument\n * @param json object containing extra DIDDoc contents\n *\n * @returns a DidDocument object resulting from the combination of both\n */\nexport function combineDidDocumentWithJson(didDoc: DidDocument, json: Record<string, unknown>) {\n const didDocJson = didDoc.toJSON()\n const combinedJson = deepMerge(didDocJson, json)\n return JsonTransformer.fromJSON(combinedJson, DidDocument)\n}\n\n/**\n * Processes the difference between a base DidDocument and a complete DidDocument\n *\n * Note: it does deep comparison based only on \"id\" field to determine whether is\n * the same object or is a different one\n *\n * @param extra complete DidDocument\n * @param base base DidDocument\n * @returns diff object\n */\nexport function didDocDiff(extra: Record<string, unknown>, base: Record<string, unknown>) {\n const output: Record<string, unknown> = {}\n for (const key in extra) {\n if (!(key in base)) {\n output[key] = extra[key]\n } else {\n // They are arrays: compare elements\n if (Array.isArray(extra[key]) && Array.isArray(base[key])) {\n // Different types: return the extra\n output[key] = []\n // biome-ignore lint/suspicious/noExplicitAny: no explanation\n const baseAsArray = base[key] as Array<any>\n // biome-ignore lint/suspicious/noExplicitAny: no explanation\n const extraAsArray = extra[key] as Array<any>\n for (const element of extraAsArray) {\n if (!baseAsArray.find((item) => item.id === element.id)) {\n ;(output[key] as Array<unknown>).push(element)\n }\n }\n } // They are both objects: do recursive diff\n else if (typeof extra[key] === 'object' && typeof base[key] === 'object') {\n output[key] = didDocDiff(extra[key] as Record<string, unknown>, base[key] as Record<string, unknown>)\n } else {\n output[key] = extra[key]\n }\n }\n }\n return output\n}\n\n/**\n * Check whether the did is a self certifying did. If the verkey is abbreviated this method\n * will always return true. Make sure that the verkey you pass in this method belongs to the\n * did passed in\n *\n * @return Boolean indicating whether the did is self certifying\n */\nexport function isSelfCertifiedIndyDid(did: string, verkey: string): boolean {\n const { namespace } = parseIndyDid(did)\n const { did: didFromVerkey } = indyDidFromNamespaceAndInitialKey(\n namespace,\n Kms.PublicJwk.fromPublicKey({\n crv: 'Ed25519',\n kty: 'OKP',\n publicKey: TypedArrayEncoder.fromBase58(verkey),\n })\n )\n\n if (didFromVerkey === did) {\n return true\n }\n\n return false\n}\n\nexport function indyDidFromNamespaceAndInitialKey(namespace: string, initialKey: Kms.PublicJwk<Kms.Ed25519PublicJwk>) {\n const buffer = Hasher.hash(initialKey.publicKey.publicKey, 'sha-256')\n\n const id = TypedArrayEncoder.toBase58(buffer.slice(0, 16))\n const verkey = TypedArrayEncoder.toBase58(initialKey.publicKey.publicKey)\n const did = `did:indy:${namespace}:${id}`\n\n return { did, id, verkey }\n}\n\n/**\n * Fetches the verification key for a given did:indy did and returns the key as a {@link Key} object.\n *\n * @throws {@link CredoError} if the did could not be resolved or the key could not be extracted\n */\nexport async function verificationPublicJwkForIndyDid(agentContext: AgentContext, did: string) {\n const didsApi = agentContext.dependencyManager.resolve(DidsApi)\n\n const { keys, didDocument } = await didsApi.resolveCreatedDidDocumentWithKeys(did)\n\n const verificationMethod = didDocument.dereferenceKey('#verkey')\n const key = keys?.find((key) => key.didDocumentRelativeKeyId === '#verkey')\n\n const publicJwk = getPublicJwkFromVerificationMethod(verificationMethod)\n if (!publicJwk.is(Kms.Ed25519PublicJwk)) {\n throw new CredoError('Expected #verkey verification mehod to be of type Ed25519')\n }\n\n publicJwk.keyId = key?.kmsKeyId ?? publicJwk.legacyKeyId\n return publicJwk\n}\n\nexport async function getPublicDid(pool: IndyVdrPool, unqualifiedDid: string) {\n const request = new GetNymRequest({ dest: unqualifiedDid })\n\n const didResponse = await pool.submitRequest(request)\n\n if (!didResponse.result.data) {\n throw new IndyVdrNotFoundError(`DID ${unqualifiedDid} not found in indy namespace ${pool.indyNamespace}`)\n }\n return JSON.parse(didResponse.result.data) as GetNymResponseData\n}\n\nexport async function getEndpointsForDid(agentContext: AgentContext, pool: IndyVdrPool, unqualifiedDid: string) {\n try {\n agentContext.config.logger.debug(`Get endpoints for did '${unqualifiedDid}' from ledger '${pool.indyNamespace}'`)\n\n const request = new GetAttribRequest({ targetDid: unqualifiedDid, raw: 'endpoint' })\n\n agentContext.config.logger.debug(\n `Submitting get endpoint ATTRIB request for did '${unqualifiedDid}' to ledger '${pool.indyNamespace}'`\n )\n const response = await pool.submitRequest(request)\n\n if (!response.result.data) {\n return null\n }\n\n const endpoints = JSON.parse(response.result.data as string)?.endpoint as IndyEndpointAttrib\n agentContext.config.logger.debug(\n `Got endpoints '${JSON.stringify(endpoints)}' for did '${unqualifiedDid}' from ledger '${pool.indyNamespace}'`,\n {\n response,\n endpoints,\n }\n )\n\n return endpoints\n } catch (error) {\n agentContext.config.logger.error(\n `Error retrieving endpoints for did '${unqualifiedDid}' from ledger '${pool.indyNamespace}'`,\n {\n error,\n }\n )\n\n throw new IndyVdrError(error)\n }\n}\n\nexport async function buildDidDocument(agentContext: AgentContext, pool: IndyVdrPool, did: string) {\n const { namespaceIdentifier } = parseIndyDid(did)\n const nym = await getPublicDid(pool, namespaceIdentifier)\n\n // Create base Did Document\n\n // For modern did:indy DIDs, we assume that GET_NYM is always a full verkey in base58.\n // For backwards compatibility, we accept a shortened verkey and convert it using previous convention\n const verkey = getFullVerkey(namespaceIdentifier, nym.verkey)\n\n const builder = indyDidDocumentFromDid(did, verkey)\n\n // If GET_NYM does not return any diddocContent, fallback to legacy GET_ATTRIB endpoint\n if (!nym.diddocContent) {\n const keyAgreementId = `${did}#key-agreement-1`\n const endpoints = await getEndpointsForDid(agentContext, pool, namespaceIdentifier)\n\n if (endpoints) {\n builder\n .addContext('https://w3id.org/security/suites/x25519-2019/v1')\n .addVerificationMethod({\n controller: did,\n id: keyAgreementId,\n publicKeyBase58: createKeyAgreementKey(verkey),\n type: 'X25519KeyAgreementKey2019',\n })\n .addKeyAgreement(keyAgreementId)\n\n // Process endpoint attrib following the same rules as for did:sov\n addServicesFromEndpointsAttrib(builder, did, endpoints, keyAgreementId)\n }\n return builder.build()\n }\n // Combine it with didDoc\n let diddocContent: Record<string, unknown>\n try {\n diddocContent = JSON.parse(nym.diddocContent)\n } catch (error) {\n agentContext.config.logger.error(`Nym diddocContent is not a valid json string: ${nym.diddocContent}`)\n throw new IndyVdrError(`Nym diddocContent failed to parse as JSON: ${error}`)\n }\n return combineDidDocumentWithJson(builder.build(), diddocContent)\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAgB,uBAAuB,KAAa,cAAsB;CACxE,MAAM,uBAAuB,GAAG,IAAI;CAEpC,MAAM,kBAAkB;AAYxB,QAVgB,IAAI,mBAAmB,IAAI,CACxC,WAAW,mDAAmD,CAC9D,sBAAsB;EACrB,YAAY;EACZ,IAAI;EACJ;EACA,MAAM;EACP,CAAC,CACD,kBAAkB,qBAAqB;;AAK5C,SAAgB,sBAAsB,QAAgB;AACpD,QAAO,kBAAkB,SAAS,yBAAyB,kBAAkB,WAAW,OAAO,CAAC,CAAC;;AAGnG,MAAM,aAAa,GAA4B,MAA+B;CAC5E,MAAMA,SAAkC,EAAE;AAE1C,MAAK,MAAM,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,EAAE,EAAE,GAAG,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CAEpE,KAAI,EAAE,QAAQ,CAAC,EAAE,KACf,QAAO,OAAO,EAAE;UACP,CAAC,EAAE,QAAQ,EAAE,KACtB,QAAO,OAAO,EAAE;UAIZ,MAAM,QAAQ,EAAE,KAAK,CACvB,KAAI,MAAM,QAAQ,EAAE,KAAK,EAAE;EACzB,MAAM,0BAAU,IAAI,KAAK;AAEzB,OAAK,MAAM,QAAQ,EAAE,KACnB,SAAQ,IAAI,KAAK;AAGnB,OAAK,MAAM,QAAQ,EAAE,KACnB,SAAQ,IAAI,KAAK;AAGnB,SAAO,OAAO,MAAM,KAAK,QAAQ;QAC5B;EAEL,MAAM,MAAM,EAAE;AACd,SAAO,OAAO,MAAM,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,KAAK,C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AAK,OAAO;AAGnD,KAAI,CAAC,IAAI,eAAe;EACtB,MAAM,iBAAiB,GAAG,IAAI;EAC9B,MAAM,YAAY,MAAM,mBAAmB,cAAc,MAAM,oBAAoB;AAEnF,MAAI,WAAW;AACb,WACG,WAAW,kDAAkD,CAC7D,sBAAsB;IACrB,YAAY;IACZ,IAAI;IACJ,iBAAiB,sBAAsB,OAAO;IAC9C,MAAM;IACP,CAAC,CACD,gBAAgB,eAAe;AAGlC,kCAA+B,SAAS,KAAK,WAAW,eAAe;;AAEzE,SAAO,QAAQ,OAAO;;CAGxB,IAAIC;AACJ,KAAI;AACF,kBAAgB,KAAK,MAAM,IAAI,cAAc;UACtC,OAAO;AACd,eAAa,OAAO,OAAO,MAAM,iDAAiD,IAAI,gBAAgB;AACtG,QAAM,IAAI,aAAa,8CAA8C,QAAQ;;AAE/E,QAAO,2BAA2B,QAAQ,OAAO,EAAE,cAAc"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Buffer, CredoError, DidCommV1Service, DidCommV2Service, DidDocumentBuilder, DidDocumentService, NewDidCommV2Service, NewDidCommV2ServiceEndpoint, TypedArrayEncoder, convertPublicKeyToX25519 } from "@credo-ts/core";
|
|
2
|
+
|
|
3
|
+
//#region src/dids/didSovUtil.ts
|
|
4
|
+
const FULL_VERKEY_REGEX = /^[1-9A-HJ-NP-Za-km-z]{43,44}$/;
|
|
5
|
+
/**
|
|
6
|
+
* Check a base58 encoded string against a regex expression to determine if it is a full valid verkey
|
|
7
|
+
* @param verkey Base58 encoded string representation of a verkey
|
|
8
|
+
* @return Boolean indicating if the string is a valid verkey
|
|
9
|
+
*/
|
|
10
|
+
function isFullVerkey(verkey) {
|
|
11
|
+
return FULL_VERKEY_REGEX.test(verkey);
|
|
12
|
+
}
|
|
13
|
+
function getFullVerkey(did, verkey) {
|
|
14
|
+
if (isFullVerkey(verkey)) return verkey;
|
|
15
|
+
const id = did.split(":").pop() ?? did;
|
|
16
|
+
const verkeyWithoutTilde = verkey.slice(1);
|
|
17
|
+
return TypedArrayEncoder.toBase58(Buffer.concat([TypedArrayEncoder.fromBase58(id), TypedArrayEncoder.fromBase58(verkeyWithoutTilde)]));
|
|
18
|
+
}
|
|
19
|
+
function sovDidDocumentFromDid(fullDid, verkey) {
|
|
20
|
+
const verificationMethodId = `${fullDid}#key-1`;
|
|
21
|
+
const keyAgreementId = `${fullDid}#key-agreement-1`;
|
|
22
|
+
const publicKeyBase58 = getFullVerkey(fullDid, verkey);
|
|
23
|
+
const publicKeyX25519 = TypedArrayEncoder.toBase58(convertPublicKeyToX25519(TypedArrayEncoder.fromBase58(publicKeyBase58)));
|
|
24
|
+
return new DidDocumentBuilder(fullDid).addContext("https://w3id.org/security/suites/ed25519-2018/v1").addContext("https://w3id.org/security/suites/x25519-2019/v1").addVerificationMethod({
|
|
25
|
+
controller: fullDid,
|
|
26
|
+
id: verificationMethodId,
|
|
27
|
+
publicKeyBase58,
|
|
28
|
+
type: "Ed25519VerificationKey2018"
|
|
29
|
+
}).addVerificationMethod({
|
|
30
|
+
controller: fullDid,
|
|
31
|
+
id: keyAgreementId,
|
|
32
|
+
publicKeyBase58: publicKeyX25519,
|
|
33
|
+
type: "X25519KeyAgreementKey2019"
|
|
34
|
+
}).addAuthentication(verificationMethodId).addAssertionMethod(verificationMethodId).addKeyAgreement(keyAgreementId);
|
|
35
|
+
}
|
|
36
|
+
function processEndpointTypes(types) {
|
|
37
|
+
const expectedTypes = [
|
|
38
|
+
"endpoint",
|
|
39
|
+
"did-communication",
|
|
40
|
+
"DIDComm",
|
|
41
|
+
"DIDCommMessaging"
|
|
42
|
+
];
|
|
43
|
+
const defaultTypes = ["endpoint", "did-communication"];
|
|
44
|
+
if (!types || types.length <= 0) return defaultTypes;
|
|
45
|
+
for (const type of types) if (!expectedTypes.includes(type)) return defaultTypes;
|
|
46
|
+
return types;
|
|
47
|
+
}
|
|
48
|
+
function endpointsAttribFromServices(services) {
|
|
49
|
+
const commTypes = [
|
|
50
|
+
"endpoint",
|
|
51
|
+
"did-communication",
|
|
52
|
+
"DIDComm",
|
|
53
|
+
"DIDCommMessaging"
|
|
54
|
+
];
|
|
55
|
+
const commServices = services.filter((item) => commTypes.includes(item.type));
|
|
56
|
+
const endpoint = commServices[0] instanceof NewDidCommV2Service ? commServices[0].firstServiceEndpointUri : commServices[0].serviceEndpoint;
|
|
57
|
+
if (typeof endpoint !== "string") throw new CredoError(`For unknown service endpoint types (${commServices[0].type}) the 'serviceEndpoint' needs to be of type 'string'`);
|
|
58
|
+
if (!commServices.every((item) => (item instanceof NewDidCommV2Service ? item.firstServiceEndpointUri : item.serviceEndpoint) === endpoint)) throw new CredoError("serviceEndpoint for all services must match");
|
|
59
|
+
const types = [];
|
|
60
|
+
const routingKeys = /* @__PURE__ */ new Set();
|
|
61
|
+
for (const commService of commServices) {
|
|
62
|
+
const commServiceType = commService.type;
|
|
63
|
+
if (types.includes(commServiceType)) throw new CredoError("Only a single communication service per type is supported");
|
|
64
|
+
types.push(commServiceType);
|
|
65
|
+
if ((commService instanceof DidCommV1Service || commService instanceof DidCommV2Service) && commService.routingKeys) for (const item of commService.routingKeys) routingKeys.add(item);
|
|
66
|
+
else if (commService instanceof NewDidCommV2Service) {
|
|
67
|
+
const firstServiceEndpoint = Array.isArray(commService.serviceEndpoint) ? commService.serviceEndpoint[0] : commService.serviceEndpoint;
|
|
68
|
+
for (const item of firstServiceEndpoint.routingKeys ?? []) routingKeys.add(item);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
endpoint,
|
|
73
|
+
types,
|
|
74
|
+
routingKeys: Array.from(routingKeys)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function addServicesFromEndpointsAttrib(builder, did, endpoints, keyAgreementId) {
|
|
78
|
+
const { endpoint, routingKeys, types, ...otherEndpoints } = endpoints;
|
|
79
|
+
if (endpoint) {
|
|
80
|
+
const processedTypes = processEndpointTypes(types);
|
|
81
|
+
if (processedTypes.includes("endpoint")) builder.addService(new DidDocumentService({
|
|
82
|
+
id: `${did}#endpoint`,
|
|
83
|
+
serviceEndpoint: endpoint,
|
|
84
|
+
type: "endpoint"
|
|
85
|
+
}));
|
|
86
|
+
if (processedTypes.includes("did-communication")) builder.addService(new DidCommV1Service({
|
|
87
|
+
id: `${did}#did-communication`,
|
|
88
|
+
serviceEndpoint: endpoint,
|
|
89
|
+
priority: 0,
|
|
90
|
+
routingKeys: routingKeys ?? [],
|
|
91
|
+
recipientKeys: [keyAgreementId],
|
|
92
|
+
accept: ["didcomm/aip2;env=rfc19"]
|
|
93
|
+
}));
|
|
94
|
+
if (processedTypes.includes("DIDCommMessaging")) builder.addService(new NewDidCommV2Service({
|
|
95
|
+
id: `${did}#didcomm-messaging-1`,
|
|
96
|
+
serviceEndpoint: new NewDidCommV2ServiceEndpoint({
|
|
97
|
+
uri: endpoint,
|
|
98
|
+
routingKeys,
|
|
99
|
+
accept: ["didcomm/v2"]
|
|
100
|
+
})
|
|
101
|
+
})).addContext("https://didcomm.org/messaging/contexts/v2");
|
|
102
|
+
if (processedTypes.includes("DIDComm")) builder.addService(new DidCommV2Service({
|
|
103
|
+
id: `${did}#didcomm-1`,
|
|
104
|
+
routingKeys,
|
|
105
|
+
accept: ["didcomm/v2"],
|
|
106
|
+
serviceEndpoint: endpoint
|
|
107
|
+
})).addContext("https://didcomm.org/messaging/contexts/v2");
|
|
108
|
+
}
|
|
109
|
+
for (const [type, endpoint$1] of Object.entries(otherEndpoints)) builder.addService(new DidDocumentService({
|
|
110
|
+
id: `${did}#${type}`,
|
|
111
|
+
serviceEndpoint: endpoint$1,
|
|
112
|
+
type
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { addServicesFromEndpointsAttrib, endpointsAttribFromServices, getFullVerkey, sovDidDocumentFromDid };
|
|
118
|
+
//# sourceMappingURL=didSovUtil.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"didSovUtil.mjs","names":["commTypes: CommEndpointType[]","types: CommEndpointType[]","endpoint"],"sources":["../../src/dids/didSovUtil.ts"],"sourcesContent":["import {\n Buffer,\n CredoError,\n convertPublicKeyToX25519,\n DidCommV1Service,\n DidCommV2Service,\n DidDocumentBuilder,\n DidDocumentService,\n NewDidCommV2Service,\n NewDidCommV2ServiceEndpoint,\n TypedArrayEncoder,\n} from '@credo-ts/core'\n\nexport type CommEndpointType = 'endpoint' | 'did-communication' | 'DIDComm' | 'DIDCommMessaging'\n\nexport interface IndyEndpointAttrib {\n endpoint?: string\n types?: Array<CommEndpointType>\n routingKeys?: string[]\n [key: string]: unknown\n}\n\nexport interface GetNymResponseData {\n did: string\n verkey: string\n role: string\n alias?: string\n diddocContent?: string\n}\n\nexport const FULL_VERKEY_REGEX = /^[1-9A-HJ-NP-Za-km-z]{43,44}$/\n\n/**\n * Check a base58 encoded string against a regex expression to determine if it is a full valid verkey\n * @param verkey Base58 encoded string representation of a verkey\n * @return Boolean indicating if the string is a valid verkey\n */\nexport function isFullVerkey(verkey: string): boolean {\n return FULL_VERKEY_REGEX.test(verkey)\n}\n\nexport function getFullVerkey(did: string, verkey: string) {\n if (isFullVerkey(verkey)) return verkey\n\n // Did could have did:xxx prefix, only take the last item after :\n const id = did.split(':').pop() ?? did\n // Verkey is prefixed with ~ if abbreviated\n const verkeyWithoutTilde = verkey.slice(1)\n\n // Create base58 encoded public key (32 bytes)\n return TypedArrayEncoder.toBase58(\n Buffer.concat([\n // Take did identifier (16 bytes)\n TypedArrayEncoder.fromBase58(id),\n // Concat the abbreviated verkey (16 bytes)\n TypedArrayEncoder.fromBase58(verkeyWithoutTilde),\n ])\n )\n}\n\nexport function sovDidDocumentFromDid(fullDid: string, verkey: string) {\n const verificationMethodId = `${fullDid}#key-1`\n const keyAgreementId = `${fullDid}#key-agreement-1`\n\n const publicKeyBase58 = getFullVerkey(fullDid, verkey)\n const publicKeyX25519 = TypedArrayEncoder.toBase58(\n convertPublicKeyToX25519(TypedArrayEncoder.fromBase58(publicKeyBase58))\n )\n\n const builder = new DidDocumentBuilder(fullDid)\n .addContext('https://w3id.org/security/suites/ed25519-2018/v1')\n .addContext('https://w3id.org/security/suites/x25519-2019/v1')\n .addVerificationMethod({\n controller: fullDid,\n id: verificationMethodId,\n publicKeyBase58: publicKeyBase58,\n type: 'Ed25519VerificationKey2018',\n })\n .addVerificationMethod({\n controller: fullDid,\n id: keyAgreementId,\n publicKeyBase58: publicKeyX25519,\n type: 'X25519KeyAgreementKey2019',\n })\n .addAuthentication(verificationMethodId)\n .addAssertionMethod(verificationMethodId)\n .addKeyAgreement(keyAgreementId)\n\n return builder\n}\n\n// Process Indy Attrib Endpoint Types according to: https://sovrin-foundation.github.io/sovrin/spec/did-method-spec-template.html > Read (Resolve) > DID Service Endpoint\nfunction processEndpointTypes(types?: string[]) {\n const expectedTypes = ['endpoint', 'did-communication', 'DIDComm', 'DIDCommMessaging']\n const defaultTypes = ['endpoint', 'did-communication']\n\n // Return default types if types \"is NOT present [or] empty\"\n if (!types || types.length <= 0) {\n return defaultTypes\n }\n\n // Return default types if types \"contain any other values\"\n for (const type of types) {\n if (!expectedTypes.includes(type)) {\n return defaultTypes\n }\n }\n\n // Return provided types\n return types\n}\n\nexport function endpointsAttribFromServices(services: DidDocumentService[]): IndyEndpointAttrib {\n const commTypes: CommEndpointType[] = ['endpoint', 'did-communication', 'DIDComm', 'DIDCommMessaging']\n const commServices = services.filter((item) => commTypes.includes(item.type as CommEndpointType))\n\n const endpoint =\n commServices[0] instanceof NewDidCommV2Service\n ? commServices[0].firstServiceEndpointUri\n : commServices[0].serviceEndpoint\n\n if (typeof endpoint !== 'string') {\n throw new CredoError(\n `For unknown service endpoint types (${commServices[0].type}) the 'serviceEndpoint' needs to be of type 'string'`\n )\n }\n\n // Check that all services use the same endpoint, as only one is accepted\n if (\n !commServices.every(\n (item) => (item instanceof NewDidCommV2Service ? item.firstServiceEndpointUri : item.serviceEndpoint) === endpoint\n )\n ) {\n throw new CredoError('serviceEndpoint for all services must match')\n }\n\n const types: CommEndpointType[] = []\n const routingKeys = new Set<string>()\n\n for (const commService of commServices) {\n const commServiceType = commService.type as CommEndpointType\n if (types.includes(commServiceType)) {\n throw new CredoError('Only a single communication service per type is supported')\n }\n\n types.push(commServiceType)\n\n if (\n (commService instanceof DidCommV1Service || commService instanceof DidCommV2Service) &&\n commService.routingKeys\n ) {\n for (const item of commService.routingKeys) {\n routingKeys.add(item)\n }\n } else if (commService instanceof NewDidCommV2Service) {\n const firstServiceEndpoint = Array.isArray(commService.serviceEndpoint)\n ? commService.serviceEndpoint[0]\n : commService.serviceEndpoint\n\n for (const item of firstServiceEndpoint.routingKeys ?? []) {\n routingKeys.add(item)\n }\n }\n }\n\n return { endpoint, types, routingKeys: Array.from(routingKeys) }\n}\n\nexport function addServicesFromEndpointsAttrib(\n builder: DidDocumentBuilder,\n did: string,\n endpoints: IndyEndpointAttrib,\n keyAgreementId: string\n) {\n const { endpoint, routingKeys, types, ...otherEndpoints } = endpoints\n\n if (endpoint) {\n const processedTypes = processEndpointTypes(types)\n\n // If 'endpoint' included in types, add id to the services array\n if (processedTypes.includes('endpoint')) {\n builder.addService(\n new DidDocumentService({\n id: `${did}#endpoint`,\n serviceEndpoint: endpoint,\n type: 'endpoint',\n })\n )\n }\n\n // If 'did-communication' included in types, add DIDComm v1 entry\n if (processedTypes.includes('did-communication')) {\n builder.addService(\n new DidCommV1Service({\n id: `${did}#did-communication`,\n serviceEndpoint: endpoint,\n priority: 0,\n routingKeys: routingKeys ?? [],\n recipientKeys: [keyAgreementId],\n accept: ['didcomm/aip2;env=rfc19'],\n })\n )\n }\n\n // If 'DIDCommMessaging' included in types, add DIDComm v2 entry\n if (processedTypes.includes('DIDCommMessaging')) {\n builder\n .addService(\n new NewDidCommV2Service({\n id: `${did}#didcomm-messaging-1`,\n serviceEndpoint: new NewDidCommV2ServiceEndpoint({\n uri: endpoint,\n routingKeys: routingKeys,\n accept: ['didcomm/v2'],\n }),\n })\n )\n .addContext('https://didcomm.org/messaging/contexts/v2')\n }\n\n // If 'DIDComm' included in types, add legacy DIDComm v2 entry\n if (processedTypes.includes('DIDComm')) {\n builder\n .addService(\n new DidCommV2Service({\n id: `${did}#didcomm-1`,\n routingKeys: routingKeys,\n accept: ['didcomm/v2'],\n serviceEndpoint: endpoint,\n })\n )\n .addContext('https://didcomm.org/messaging/contexts/v2')\n }\n }\n\n // Add other endpoint types\n for (const [type, endpoint] of Object.entries(otherEndpoints)) {\n builder.addService(\n new DidDocumentService({\n id: `${did}#${type}`,\n serviceEndpoint: endpoint as string,\n type,\n })\n )\n }\n}\n"],"mappings":";;;AA8BA,MAAa,oBAAoB;;;;;;AAOjC,SAAgB,aAAa,QAAyB;AACpD,QAAO,kBAAkB,KAAK,OAAO;;AAGvC,SAAgB,cAAc,KAAa,QAAgB;AACzD,KAAI,aAAa,OAAO,CAAE,QAAO;CAGjC,MAAM,KAAK,IAAI,MAAM,IAAI,CAAC,KAAK,IAAI;CAEnC,MAAM,qBAAqB,OAAO,MAAM,EAAE;AAG1C,QAAO,kBAAkB,SACvB,OAAO,OAAO,CAEZ,kBAAkB,WAAW,GAAG,EAEhC,kBAAkB,WAAW,mBAAmB,CACjD,CAAC,CACH;;AAGH,SAAgB,sBAAsB,SAAiB,QAAgB;CACrE,MAAM,uBAAuB,GAAG,QAAQ;CACxC,MAAM,iBAAiB,GAAG,QAAQ;CAElC,MAAM,kBAAkB,cAAc,SAAS,OAAO;CACtD,MAAM,kBAAkB,kBAAkB,SACxC,yBAAyB,kBAAkB,WAAW,gBAAgB,CAAC,CACxE;AAqBD,QAnBgB,IAAI,mBAAmB,QAAQ,CAC5C,WAAW,mDAAmD,CAC9D,WAAW,kDAAkD,CAC7D,sBAAsB;EACrB,YAAY;EACZ,IAAI;EACa;EACjB,MAAM;EACP,CAAC,CACD,sBAAsB;EACrB,YAAY;EACZ,IAAI;EACJ,iBAAiB;EACjB,MAAM;EACP,CAAC,CACD,k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K;;;AAK3B,QAAO;EAAE;EAAU;EAAO,aAAa,MAAM,KAAK,YAAY;EAAE;;AAGlE,SAAgB,+BACd,SACA,KACA,WACA,gBACA;CACA,MAAM,EAAE,UAAU,aAAa,OAAO,GAAG,mBAAmB;AAE5D,KAAI,UAAU;EACZ,MAAM,iBAAiB,qBAAqB,MAAM;AAGlD,MAAI,eAAe,SAAS,WAAW,CACrC,SAAQ,WACN,IAAI,mBAAmB;GACrB,IAAI,GAAG,IAAI;GACX,iBAAiB;GACjB,MAAM;GACP,CAAC,CACH;AAIH,MAAI,eAAe,SAAS,oBAAoB,CAC9C,SAAQ,WACN,IAAI,iBAAiB;GACnB,IAAI,GAAG,IAAI;GACX,iBAAiB;GACjB,UAAU;GACV,aAAa,eAAe,EAAE;GAC9B,eAAe,CAAC,eAAe;GAC/B,QAAQ,CAAC,yBAAyB;GACnC,CAAC,CACH;AAIH,MAAI,eAAe,SAAS,mBAAmB,CAC7C,SACG,WACC,IAAI,oBAAoB;GACtB,IAAI,GAAG,IAAI;GACX,iBAAiB,IAAI,4BAA4B;IAC/C,KAAK;IACQ;IACb,QAAQ,CAAC,aAAa;IACvB,CAAC;GACH,CAAC,CACH,CACA,WAAW,4CAA4C;AAI5D,MAAI,eAAe,SAAS,UAAU,CACpC,SACG,WACC,IAAI,iBAAiB;GACnB,IAAI,GAAG,IAAI;GACE;GACb,QAAQ,CAAC,aAAa;GACtB,iBAAiB;GAClB,CAAC,CACH,CACA,WAAW,4CAA4C;;AAK9D,MAAK,MAAM,CAAC,MAAMC,eAAa,OAAO,QAAQ,eAAe,CAC3D,SAAQ,WACN,IAAI,mBAAmB;EACrB,IAAI,GAAG,IAAI,GAAG;EACd,iBAAiBA;EACjB;EACD,CAAC,CACH"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CredoError } from "@credo-ts/core";
|
|
2
|
+
|
|
3
|
+
//#region src/error/IndyVdrError.ts
|
|
4
|
+
var IndyVdrError = class extends CredoError {
|
|
5
|
+
constructor(message, { cause } = {}) {
|
|
6
|
+
super(message, { cause });
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { IndyVdrError };
|
|
12
|
+
//# sourceMappingURL=IndyVdrError.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndyVdrError.mjs","names":[],"sources":["../../src/error/IndyVdrError.ts"],"sourcesContent":["import { CredoError } from '@credo-ts/core'\n\nexport class IndyVdrError extends CredoError {\n public constructor(message: string, { cause }: { cause?: Error } = {}) {\n super(message, { cause })\n }\n}\n"],"mappings":";;;AAEA,IAAa,eAAb,cAAkC,WAAW;CAC3C,AAAO,YAAY,SAAiB,EAAE,UAA6B,EAAE,EAAE;AACrE,QAAM,SAAS,EAAE,OAAO,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IndyVdrError } from "./IndyVdrError.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/error/IndyVdrNotConfiguredError.ts
|
|
4
|
+
var IndyVdrNotConfiguredError = class extends IndyVdrError {
|
|
5
|
+
constructor(message, { cause } = {}) {
|
|
6
|
+
super(message, { cause });
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { IndyVdrNotConfiguredError };
|
|
12
|
+
//# sourceMappingURL=IndyVdrNotConfiguredError.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndyVdrNotConfiguredError.mjs","names":[],"sources":["../../src/error/IndyVdrNotConfiguredError.ts"],"sourcesContent":["import { IndyVdrError } from './IndyVdrError'\n\nexport class IndyVdrNotConfiguredError extends IndyVdrError {\n public constructor(message: string, { cause }: { cause?: Error } = {}) {\n super(message, { cause })\n }\n}\n"],"mappings":";;;AAEA,IAAa,4BAAb,cAA+C,aAAa;CAC1D,AAAO,YAAY,SAAiB,EAAE,UAA6B,EAAE,EAAE;AACrE,QAAM,SAAS,EAAE,OAAO,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IndyVdrError } from "./IndyVdrError.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/error/IndyVdrNotFound.ts
|
|
4
|
+
var IndyVdrNotFoundError = class extends IndyVdrError {
|
|
5
|
+
constructor(message, { cause } = {}) {
|
|
6
|
+
super(message, { cause });
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { IndyVdrNotFoundError };
|
|
12
|
+
//# sourceMappingURL=IndyVdrNotFound.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndyVdrNotFound.mjs","names":[],"sources":["../../src/error/IndyVdrNotFound.ts"],"sourcesContent":["import { IndyVdrError } from './IndyVdrError'\n\nexport class IndyVdrNotFoundError extends IndyVdrError {\n public constructor(message: string, { cause }: { cause?: Error } = {}) {\n super(message, { cause })\n }\n}\n"],"mappings":";;;AAEA,IAAa,uBAAb,cAA0C,aAAa;CACrD,AAAO,YAAY,SAAiB,EAAE,UAA6B,EAAE,EAAE;AACrE,QAAM,SAAS,EAAE,OAAO,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IndyVdrAnonCredsRegistry, IndyVdrRegisterCredentialDefinition, IndyVdrRegisterCredentialDefinitionExternalCreateOptions, IndyVdrRegisterCredentialDefinitionExternalSubmitOptions, IndyVdrRegisterCredentialDefinitionInternalOptions, IndyVdrRegisterCredentialDefinitionOptions, IndyVdrRegisterCredentialDefinitionReturn, IndyVdrRegisterCredentialDefinitionReturnStateAction, IndyVdrRegisterRevocationRegistryDefinition, IndyVdrRegisterRevocationRegistryDefinitionExternalCreateOptions, IndyVdrRegisterRevocationRegistryDefinitionExternalSubmitOptions, IndyVdrRegisterRevocationRegistryDefinitionInternalOptions, IndyVdrRegisterRevocationRegistryDefinitionOptions, IndyVdrRegisterRevocationRegistryDefinitionReturn, IndyVdrRegisterRevocationRegistryDefinitionReturnStateAction, IndyVdrRegisterRevocationStatusList, IndyVdrRegisterRevocationStatusListExternalCreateOptions, IndyVdrRegisterRevocationStatusListExternalSubmitOptions, IndyVdrRegisterRevocationStatusListInternalOptions, IndyVdrRegisterRevocationStatusListOptions, IndyVdrRegisterRevocationStatusListReturn, IndyVdrRegisterRevocationStatusListReturnStateAction, IndyVdrRegisterSchema, IndyVdrRegisterSchemaExternalCreateOptions, IndyVdrRegisterSchemaExternalSubmitOptions, IndyVdrRegisterSchemaInternalOptions, IndyVdrRegisterSchemaOptions, IndyVdrRegisterSchemaReturn, IndyVdrRegisterSchemaReturnStateAction } from "./anoncreds/IndyVdrAnonCredsRegistry.mjs";
|
|
2
|
+
import "./anoncreds/index.mjs";
|
|
3
|
+
import { IndyVdrDidCreateOptions, IndyVdrDidCreateResult, IndyVdrIndyDidRegistrar } from "./dids/IndyVdrIndyDidRegistrar.mjs";
|
|
4
|
+
import { IndyVdrIndyDidResolver } from "./dids/IndyVdrIndyDidResolver.mjs";
|
|
5
|
+
import { IndyVdrSovDidResolver } from "./dids/IndyVdrSovDidResolver.mjs";
|
|
6
|
+
import "./dids/index.mjs";
|
|
7
|
+
import { IndyVdrPoolConfig } from "./pool/IndyVdrPool.mjs";
|
|
8
|
+
import { IndyVdrModuleConfig, IndyVdrModuleConfigOptions } from "./IndyVdrModuleConfig.mjs";
|
|
9
|
+
import { IndyVdrPoolService } from "./pool/IndyVdrPoolService.mjs";
|
|
10
|
+
import "./pool/index.mjs";
|
|
11
|
+
import { IndyVdrModule } from "./IndyVdrModule.mjs";
|
|
12
|
+
export { IndyVdrAnonCredsRegistry, type IndyVdrDidCreateOptions, type IndyVdrDidCreateResult, IndyVdrIndyDidRegistrar, IndyVdrIndyDidResolver, IndyVdrModule, IndyVdrModuleConfig, IndyVdrModuleConfigOptions, type IndyVdrPoolConfig, IndyVdrPoolService, IndyVdrRegisterCredentialDefinition, IndyVdrRegisterCredentialDefinitionExternalCreateOptions, IndyVdrRegisterCredentialDefinitionExternalSubmitOptions, IndyVdrRegisterCredentialDefinitionInternalOptions, IndyVdrRegisterCredentialDefinitionOptions, IndyVdrRegisterCredentialDefinitionReturn, IndyVdrRegisterCredentialDefinitionReturnStateAction, IndyVdrRegisterRevocationRegistryDefinition, IndyVdrRegisterRevocationRegistryDefinitionExternalCreateOptions, IndyVdrRegisterRevocationRegistryDefinitionExternalSubmitOptions, IndyVdrRegisterRevocationRegistryDefinitionInternalOptions, IndyVdrRegisterRevocationRegistryDefinitionOptions, IndyVdrRegisterRevocationRegistryDefinitionReturn, IndyVdrRegisterRevocationRegistryDefinitionReturnStateAction, IndyVdrRegisterRevocationStatusList, IndyVdrRegisterRevocationStatusListExternalCreateOptions, IndyVdrRegisterRevocationStatusListExternalSubmitOptions, IndyVdrRegisterRevocationStatusListInternalOptions, IndyVdrRegisterRevocationStatusListOptions, IndyVdrRegisterRevocationStatusListReturn, IndyVdrRegisterRevocationStatusListReturnStateAction, IndyVdrRegisterSchema, IndyVdrRegisterSchemaExternalCreateOptions, IndyVdrRegisterSchemaExternalSubmitOptions, IndyVdrRegisterSchemaInternalOptions, IndyVdrRegisterSchemaOptions, IndyVdrRegisterSchemaReturn, IndyVdrRegisterSchemaReturnStateAction, IndyVdrSovDidResolver };
|
package/build/index.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IndyVdrModuleConfig } from "./IndyVdrModuleConfig.mjs";
|
|
2
|
+
import { IndyVdrPoolService } from "./pool/IndyVdrPoolService.mjs";
|
|
3
|
+
import "./pool/index.mjs";
|
|
4
|
+
import { IndyVdrAnonCredsRegistry } from "./anoncreds/IndyVdrAnonCredsRegistry.mjs";
|
|
5
|
+
import "./anoncreds/index.mjs";
|
|
6
|
+
import { IndyVdrIndyDidRegistrar } from "./dids/IndyVdrIndyDidRegistrar.mjs";
|
|
7
|
+
import { IndyVdrIndyDidResolver } from "./dids/IndyVdrIndyDidResolver.mjs";
|
|
8
|
+
import { IndyVdrSovDidResolver } from "./dids/IndyVdrSovDidResolver.mjs";
|
|
9
|
+
import "./dids/index.mjs";
|
|
10
|
+
import { IndyVdrModule } from "./IndyVdrModule.mjs";
|
|
11
|
+
|
|
12
|
+
export { IndyVdrAnonCredsRegistry, IndyVdrIndyDidRegistrar, IndyVdrIndyDidResolver, IndyVdrModule, IndyVdrModuleConfig, IndyVdrPoolService, IndyVdrSovDidResolver };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { AgentContext, Kms } from "@credo-ts/core";
|
|
2
|
+
import * as _hyperledger_indy_vdr_shared0 from "@hyperledger/indy-vdr-shared";
|
|
3
|
+
import { IndyVdrRequest, RequestResponseType } from "@hyperledger/indy-vdr-shared";
|
|
4
|
+
|
|
5
|
+
//#region src/pool/IndyVdrPool.d.ts
|
|
6
|
+
interface TransactionAuthorAgreement {
|
|
7
|
+
version?: `${number}.${number}` | `${number}`;
|
|
8
|
+
acceptanceMechanism: string;
|
|
9
|
+
}
|
|
10
|
+
interface AuthorAgreement {
|
|
11
|
+
digest: string;
|
|
12
|
+
version: string;
|
|
13
|
+
text: string;
|
|
14
|
+
ratification_ts: number;
|
|
15
|
+
acceptanceMechanisms: AcceptanceMechanisms;
|
|
16
|
+
}
|
|
17
|
+
interface AcceptanceMechanisms {
|
|
18
|
+
aml: Record<string, string>;
|
|
19
|
+
amlContext: string;
|
|
20
|
+
version: string;
|
|
21
|
+
}
|
|
22
|
+
interface IndyVdrPoolConfig {
|
|
23
|
+
genesisTransactions: string;
|
|
24
|
+
isProduction: boolean;
|
|
25
|
+
indyNamespace: string;
|
|
26
|
+
transactionAuthorAgreement?: TransactionAuthorAgreement;
|
|
27
|
+
connectOnStartup?: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare class IndyVdrPool {
|
|
30
|
+
private _pool?;
|
|
31
|
+
private poolConfig;
|
|
32
|
+
authorAgreement?: AuthorAgreement | null;
|
|
33
|
+
constructor(poolConfig: IndyVdrPoolConfig);
|
|
34
|
+
get indyNamespace(): string;
|
|
35
|
+
get config(): IndyVdrPoolConfig;
|
|
36
|
+
get isOpen(): boolean;
|
|
37
|
+
connect(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Refreshes the connection to the pool.
|
|
40
|
+
*/
|
|
41
|
+
refreshConnection(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Get the transactions for a pool
|
|
44
|
+
*/
|
|
45
|
+
get transactions(): Promise<_hyperledger_indy_vdr_shared0.Transactions>;
|
|
46
|
+
private get pool();
|
|
47
|
+
close(): void;
|
|
48
|
+
prepareWriteRequest<Request extends IndyVdrRequest>(agentContext: AgentContext, request: Request, signingKey: Kms.PublicJwk<Kms.Ed25519PublicJwk>, endorserDid?: string): Promise<Request>;
|
|
49
|
+
/**
|
|
50
|
+
* This method submits a request to the ledger.
|
|
51
|
+
* It does only submit the request. It does not modify it in any way.
|
|
52
|
+
* To create the request, use the `prepareWriteRequest` method.
|
|
53
|
+
* @param writeRequest
|
|
54
|
+
*/
|
|
55
|
+
submitRequest<Request extends IndyVdrRequest>(writeRequest: Request): Promise<RequestResponseType<Request>>;
|
|
56
|
+
private appendTaa;
|
|
57
|
+
private getTransactionAuthorAgreement;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { AcceptanceMechanisms, AuthorAgreement, IndyVdrPool, IndyVdrPoolConfig, TransactionAuthorAgreement };
|
|
61
|
+
//# sourceMappingURL=IndyVdrPool.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndyVdrPool.d.mts","names":[],"sources":["../../src/pool/IndyVdrPool.ts"],"sourcesContent":[],"mappings":";;;;;UAYiB,0BAAA;;;AAAjB;AAKiB,UAAA,eAAA,CAKO;EAGP,MAAA,EAAA,MAAA;EAMA,OAAA,EAAA,MAAA;EAQJ,IAAA,EAAA,MAAA;EAGc,eAAA,EAAA,MAAA;EAEM,oBAAA,EAtBT,oBAsBS;;AA+BG,UAlDnB,oBAAA,CAkDmB;EAAO,GAAA,EAjDpC,MAiDoC,CAAA,MAAA,EAAA,MAAA,CASlB;EAAA,UAAA,EAAA,MAAA;EAoB0B,OAAA,EAAA,MAAA;;AAEtC,UA3EI,iBAAA,CA2EJ;EACiB,mBAAI,EAAA,MAAA;EAAlB,YAAI,EAAA,OAAA;EACI,aAAA,EAAA,MAAA;EAAA,0BAAA,CAAA,EAzEO,0BAyEP;EA6BqB,gBAAA,CAAA,EAAA,OAAA;;AAEZ,cApGpB,WAAA,CAoGoB;EAApB,QAAA,KAAA;EAAR,QAAA,UAAA;EAAO,eAAA,CAAA,EAjGe,eAiGf,GAAA,IAAA;0BA/FqB;;gBAQd;;;;;;uBAuBiB;;;;sBASX,QATkB,6BAAA,CASlB,YAAA;;;sCAoB0B,8BACjC,uBACL,qBACG,GAAA,CAAI,UAAU,GAAA,CAAI,0CACV,QAAA;;;;;;;gCA6BqB,8BAC3B,UACb,QAAQ,oBAAoB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { IndyVdrError } from "../error/IndyVdrError.mjs";
|
|
2
|
+
import "../error/index.mjs";
|
|
3
|
+
import { parseIndyDid } from "@credo-ts/anoncreds";
|
|
4
|
+
import { AgentContext, Kms, TypedArrayEncoder } from "@credo-ts/core";
|
|
5
|
+
import { GetAcceptanceMechanismsRequest, GetTransactionAuthorAgreementRequest, PoolCreate, indyVdr } from "@hyperledger/indy-vdr-shared";
|
|
6
|
+
|
|
7
|
+
//#region src/pool/IndyVdrPool.ts
|
|
8
|
+
var IndyVdrPool = class {
|
|
9
|
+
constructor(poolConfig) {
|
|
10
|
+
this.poolConfig = poolConfig;
|
|
11
|
+
}
|
|
12
|
+
get indyNamespace() {
|
|
13
|
+
return this.poolConfig.indyNamespace;
|
|
14
|
+
}
|
|
15
|
+
get config() {
|
|
16
|
+
return this.poolConfig;
|
|
17
|
+
}
|
|
18
|
+
get isOpen() {
|
|
19
|
+
return this._pool !== void 0;
|
|
20
|
+
}
|
|
21
|
+
connect() {
|
|
22
|
+
if (this._pool) return;
|
|
23
|
+
this._pool = new PoolCreate({ parameters: { transactions: this.config.genesisTransactions } });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Refreshes the connection to the pool.
|
|
27
|
+
*/
|
|
28
|
+
async refreshConnection() {
|
|
29
|
+
if (this._pool) await this._pool.refresh();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the transactions for a pool
|
|
33
|
+
*/
|
|
34
|
+
get transactions() {
|
|
35
|
+
return this.pool.transactions;
|
|
36
|
+
}
|
|
37
|
+
get pool() {
|
|
38
|
+
if (!this._pool) this.connect();
|
|
39
|
+
if (!this._pool) throw new IndyVdrError("Pool is not connected.");
|
|
40
|
+
return this._pool;
|
|
41
|
+
}
|
|
42
|
+
close() {
|
|
43
|
+
if (!this._pool) throw new IndyVdrError("Can't close pool. Pool is not connected");
|
|
44
|
+
}
|
|
45
|
+
async prepareWriteRequest(agentContext, request, signingKey, endorserDid) {
|
|
46
|
+
const kms = agentContext.dependencyManager.resolve(Kms.KeyManagementApi);
|
|
47
|
+
await this.appendTaa(request);
|
|
48
|
+
if (endorserDid) request.setEndorser({ endorser: parseIndyDid(endorserDid).namespaceIdentifier });
|
|
49
|
+
const { signature } = await kms.sign({
|
|
50
|
+
data: TypedArrayEncoder.fromString(request.signatureInput),
|
|
51
|
+
algorithm: "EdDSA",
|
|
52
|
+
keyId: signingKey.keyId
|
|
53
|
+
});
|
|
54
|
+
request.setSignature({ signature });
|
|
55
|
+
return request;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* This method submits a request to the ledger.
|
|
59
|
+
* It does only submit the request. It does not modify it in any way.
|
|
60
|
+
* To create the request, use the `prepareWriteRequest` method.
|
|
61
|
+
* @param writeRequest
|
|
62
|
+
*/
|
|
63
|
+
async submitRequest(writeRequest) {
|
|
64
|
+
return await this.pool.submitRequest(writeRequest);
|
|
65
|
+
}
|
|
66
|
+
async appendTaa(request) {
|
|
67
|
+
const authorAgreement = await this.getTransactionAuthorAgreement();
|
|
68
|
+
const poolTaa = this.config.transactionAuthorAgreement;
|
|
69
|
+
if (authorAgreement == null) return request;
|
|
70
|
+
if (!poolTaa) throw new IndyVdrError(`Please, specify a transaction author agreement with version and acceptance mechanism. ${JSON.stringify(authorAgreement)}`);
|
|
71
|
+
if (authorAgreement.version !== poolTaa.version || !authorAgreement.acceptanceMechanisms.aml[poolTaa.acceptanceMechanism]) throw new IndyVdrError(`Unable to satisfy matching TAA with mechanism ${JSON.stringify(poolTaa.acceptanceMechanism)} and version ${poolTaa.version} in pool.\n Found ${JSON.stringify(authorAgreement.acceptanceMechanisms.aml)} and version ${authorAgreement.version} in pool.`);
|
|
72
|
+
const acceptance = indyVdr.prepareTxnAuthorAgreementAcceptance({
|
|
73
|
+
text: authorAgreement.text,
|
|
74
|
+
version: authorAgreement.version,
|
|
75
|
+
taaDigest: authorAgreement.digest,
|
|
76
|
+
time: Math.floor(Date.now() / 1e3),
|
|
77
|
+
acceptanceMechanismType: poolTaa.acceptanceMechanism
|
|
78
|
+
});
|
|
79
|
+
request.setTransactionAuthorAgreementAcceptance({ acceptance: JSON.parse(acceptance) });
|
|
80
|
+
}
|
|
81
|
+
async getTransactionAuthorAgreement() {
|
|
82
|
+
if (this.authorAgreement !== void 0) return this.authorAgreement;
|
|
83
|
+
const taaRequest = new GetTransactionAuthorAgreementRequest({});
|
|
84
|
+
const taaResponse = await this.submitRequest(taaRequest);
|
|
85
|
+
const acceptanceMechanismRequest = new GetAcceptanceMechanismsRequest({});
|
|
86
|
+
const acceptanceMechanismResponse = await this.submitRequest(acceptanceMechanismRequest);
|
|
87
|
+
const taaData = taaResponse.result.data;
|
|
88
|
+
if (taaData == null) {
|
|
89
|
+
this.authorAgreement = null;
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const authorAgreement = taaData;
|
|
93
|
+
const acceptanceMechanisms = acceptanceMechanismResponse.result.data;
|
|
94
|
+
this.authorAgreement = {
|
|
95
|
+
...authorAgreement,
|
|
96
|
+
acceptanceMechanisms
|
|
97
|
+
};
|
|
98
|
+
return this.authorAgreement;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { IndyVdrPool };
|
|
104
|
+
//# sourceMappingURL=IndyVdrPool.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndyVdrPool.mjs","names":[],"sources":["../../src/pool/IndyVdrPool.ts"],"sourcesContent":["import { parseIndyDid } from '@credo-ts/anoncreds'\nimport { AgentContext, Kms, TypedArrayEncoder } from '@credo-ts/core'\nimport type { IndyVdrRequest, IndyVdrPool as indyVdrPool, RequestResponseType } from '@hyperledger/indy-vdr-shared'\nimport {\n GetAcceptanceMechanismsRequest,\n GetTransactionAuthorAgreementRequest,\n indyVdr,\n PoolCreate,\n} from '@hyperledger/indy-vdr-shared'\n\nimport { IndyVdrError } from '../error'\n\nexport interface TransactionAuthorAgreement {\n version?: `${number}.${number}` | `${number}`\n acceptanceMechanism: string\n}\n\nexport interface AuthorAgreement {\n digest: string\n version: string\n text: string\n ratification_ts: number\n acceptanceMechanisms: AcceptanceMechanisms\n}\n\nexport interface AcceptanceMechanisms {\n aml: Record<string, string>\n amlContext: string\n version: string\n}\n\nexport interface IndyVdrPoolConfig {\n genesisTransactions: string\n isProduction: boolean\n indyNamespace: string\n transactionAuthorAgreement?: TransactionAuthorAgreement\n connectOnStartup?: boolean\n}\n\nexport class IndyVdrPool {\n private _pool?: indyVdrPool\n private poolConfig: IndyVdrPoolConfig\n public authorAgreement?: AuthorAgreement | null\n\n public constructor(poolConfig: IndyVdrPoolConfig) {\n this.poolConfig = poolConfig\n }\n\n public get indyNamespace(): string {\n return this.poolConfig.indyNamespace\n }\n\n public get config() {\n return this.poolConfig\n }\n\n public get isOpen() {\n return this._pool !== undefined\n }\n\n public connect() {\n if (this._pool) {\n return\n }\n\n this._pool = new PoolCreate({\n parameters: {\n transactions: this.config.genesisTransactions,\n },\n })\n }\n\n /**\n * Refreshes the connection to the pool.\n */\n public async refreshConnection(): Promise<void> {\n if (this._pool) {\n await this._pool.refresh()\n }\n }\n\n /**\n * Get the transactions for a pool\n */\n public get transactions() {\n return this.pool.transactions\n }\n\n private get pool(): indyVdrPool {\n if (!this._pool) this.connect()\n if (!this._pool) throw new IndyVdrError('Pool is not connected.')\n\n return this._pool\n }\n\n public close() {\n if (!this._pool) {\n throw new IndyVdrError(\"Can't close pool. Pool is not connected\")\n }\n\n // FIXME: Currently, the close method is not working correctly in the indy-vdr-shared package\n // this.pool.close()\n }\n\n public async prepareWriteRequest<Request extends IndyVdrRequest>(\n agentContext: AgentContext,\n request: Request,\n signingKey: Kms.PublicJwk<Kms.Ed25519PublicJwk>,\n endorserDid?: string\n ) {\n const kms = agentContext.dependencyManager.resolve(Kms.KeyManagementApi)\n await this.appendTaa(request)\n\n if (endorserDid) {\n request.setEndorser({ endorser: parseIndyDid(endorserDid).namespaceIdentifier })\n }\n\n const { signature } = await kms.sign({\n data: TypedArrayEncoder.fromString(request.signatureInput),\n algorithm: 'EdDSA',\n keyId: signingKey.keyId,\n })\n\n request.setSignature({\n signature,\n })\n\n return request\n }\n\n /**\n * This method submits a request to the ledger.\n * It does only submit the request. It does not modify it in any way.\n * To create the request, use the `prepareWriteRequest` method.\n * @param writeRequest\n */\n\n public async submitRequest<Request extends IndyVdrRequest>(\n writeRequest: Request\n ): Promise<RequestResponseType<Request>> {\n return await this.pool.submitRequest(writeRequest)\n }\n\n private async appendTaa(request: IndyVdrRequest) {\n const authorAgreement = await this.getTransactionAuthorAgreement()\n const poolTaa = this.config.transactionAuthorAgreement\n\n // If ledger does not have TAA, we can just send request\n if (authorAgreement == null) {\n return request\n }\n\n // Ledger has taa but user has not specified which one to use\n if (!poolTaa) {\n throw new IndyVdrError(\n `Please, specify a transaction author agreement with version and acceptance mechanism. ${JSON.stringify(\n authorAgreement\n )}`\n )\n }\n\n // Throw an error if the pool doesn't have the specified version and acceptance mechanism\n if (\n authorAgreement.version !== poolTaa.version ||\n !authorAgreement.acceptanceMechanisms.aml[poolTaa.acceptanceMechanism]\n ) {\n // Throw an error with a helpful message\n const errMessage = `Unable to satisfy matching TAA with mechanism ${JSON.stringify(\n poolTaa.acceptanceMechanism\n )} and version ${poolTaa.version} in pool.\\n Found ${JSON.stringify(\n authorAgreement.acceptanceMechanisms.aml\n )} and version ${authorAgreement.version} in pool.`\n throw new IndyVdrError(errMessage)\n }\n\n const acceptance = indyVdr.prepareTxnAuthorAgreementAcceptance({\n text: authorAgreement.text,\n version: authorAgreement.version,\n taaDigest: authorAgreement.digest,\n time: Math.floor(Date.now() / 1000),\n acceptanceMechanismType: poolTaa.acceptanceMechanism,\n })\n\n request.setTransactionAuthorAgreementAcceptance({\n acceptance: JSON.parse(acceptance),\n })\n }\n\n private async getTransactionAuthorAgreement(): Promise<AuthorAgreement | null> {\n // TODO Replace this condition with memoization\n if (this.authorAgreement !== undefined) {\n return this.authorAgreement\n }\n\n const taaRequest = new GetTransactionAuthorAgreementRequest({})\n const taaResponse = await this.submitRequest(taaRequest)\n\n const acceptanceMechanismRequest = new GetAcceptanceMechanismsRequest({})\n const acceptanceMechanismResponse = await this.submitRequest(acceptanceMechanismRequest)\n\n const taaData = taaResponse.result.data\n\n // TAA can be null\n if (taaData == null) {\n this.authorAgreement = null\n return null\n }\n\n // If TAA is not null, we can be sure AcceptanceMechanisms is also not null\n const authorAgreement = taaData as Omit<AuthorAgreement, 'acceptanceMechanisms'>\n\n const acceptanceMechanisms = acceptanceMechanismResponse.result.data as AcceptanceMechanisms\n this.authorAgreement = {\n ...authorAgreement,\n acceptanceMechanisms,\n }\n\n return this.authorAgreement\n }\n}\n"],"mappings":";;;;;;;AAuCA,IAAa,cAAb,MAAyB;CAKvB,AAAO,YAAY,YAA+B;AAChD,OAAK,aAAa;;CAGpB,IAAW,gBAAwB;AACjC,SAAO,KAAK,WAAW;;CAGzB,IAAW,SAAS;AAClB,S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qB,IAAI,QAAQ,qBAQlD,OAAM,IAAI,aALS,iDAAiD,KAAK,UACvE,QAAQ,oBACT,CAAC,eAAe,QAAQ,QAAQ,oBAAoB,KAAK,UACxD,gBAAgB,qBAAqB,IACtC,CAAC,eAAe,gBAAgB,QAAQ,WACP;EAGpC,MAAM,aAAa,QAAQ,oCAAoC;GAC7D,MAAM,gBAAgB;GACtB,SAAS,gBAAgB;GACzB,WAAW,gBAAgB;GAC3B,MAAM,KAAK,MAAM,KAAK,KAAK,GAAG,IAAK;GACnC,yBAAyB,QAAQ;GAClC,CAAC;AAEF,UAAQ,wCAAwC,EAC9C,YAAY,KAAK,MAAM,WAAW,EACnC,CAAC;;CAGJ,MAAc,gCAAiE;AAE7E,MAAI,KAAK,oBAAoB,OAC3B,QAAO,KAAK;EAGd,MAAM,aAAa,IAAI,qCAAqC,EAAE,CAAC;EAC/D,MAAM,cAAc,MAAM,KAAK,cAAc,WAAW;EAExD,MAAM,6BAA6B,IAAI,+BAA+B,EAAE,CAAC;EACzE,MAAM,8BAA8B,MAAM,KAAK,cAAc,2BAA2B;EAExF,MAAM,UAAU,YAAY,OAAO;AAGnC,MAAI,WAAW,MAAM;AACnB,QAAK,kBAAkB;AACvB,UAAO;;EAIT,MAAM,kBAAkB;EAExB,MAAM,uBAAuB,4BAA4B,OAAO;AAChE,OAAK,kBAAkB;GACrB,GAAG;GACH;GACD;AAED,SAAO,KAAK"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { IndyVdrPool, IndyVdrPoolConfig } from "./IndyVdrPool.mjs";
|
|
2
|
+
import { IndyVdrModuleConfig } from "../IndyVdrModuleConfig.mjs";
|
|
3
|
+
import { AgentContext, Logger } from "@credo-ts/core";
|
|
4
|
+
import * as _hyperledger_indy_vdr_shared0 from "@hyperledger/indy-vdr-shared";
|
|
5
|
+
|
|
6
|
+
//#region src/pool/IndyVdrPoolService.d.ts
|
|
7
|
+
interface CachedDidResponse {
|
|
8
|
+
nymResponse: {
|
|
9
|
+
did: string;
|
|
10
|
+
verkey: string;
|
|
11
|
+
};
|
|
12
|
+
indyNamespace: string;
|
|
13
|
+
}
|
|
14
|
+
declare class IndyVdrPoolService {
|
|
15
|
+
pools: IndyVdrPool[];
|
|
16
|
+
private logger;
|
|
17
|
+
private indyVdrModuleConfig;
|
|
18
|
+
constructor(logger: Logger, indyVdrModuleConfig: IndyVdrModuleConfig);
|
|
19
|
+
/**
|
|
20
|
+
* Get the most appropriate pool for the given did.
|
|
21
|
+
* If the did is a qualified indy did, the pool will be determined based on the namespace.
|
|
22
|
+
* If it is a legacy unqualified indy did, the pool will be determined based on the algorithm as described in this document:
|
|
23
|
+
* https://docs.google.com/document/d/109C_eMsuZnTnYe2OAd02jAts1vC4axwEKIq7_4dnNVA/edit
|
|
24
|
+
*
|
|
25
|
+
* This method will optionally return a nym response when the did has been resolved to determine the ledger
|
|
26
|
+
* either now or in the past. The nymResponse can be used to prevent multiple ledger quries fetching the same
|
|
27
|
+
* did
|
|
28
|
+
*/
|
|
29
|
+
getPoolForDid(agentContext: AgentContext, did: string): Promise<{
|
|
30
|
+
pool: IndyVdrPool;
|
|
31
|
+
nymResponse?: CachedDidResponse['nymResponse'];
|
|
32
|
+
}>;
|
|
33
|
+
private getPoolForLegacyDid;
|
|
34
|
+
private getSettledDidResponsesFromPools;
|
|
35
|
+
/**
|
|
36
|
+
* Refresh the pool connections asynchronously
|
|
37
|
+
*/
|
|
38
|
+
refreshPoolConnections(): Promise<PromiseSettledResult<void>[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Get all pool transactions
|
|
41
|
+
*/
|
|
42
|
+
getAllPoolTransactions(): Promise<PromiseSettledResult<{
|
|
43
|
+
config: IndyVdrPoolConfig;
|
|
44
|
+
transactions: _hyperledger_indy_vdr_shared0.Transactions;
|
|
45
|
+
}>[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Get the most appropriate pool for the given indyNamespace
|
|
48
|
+
*/
|
|
49
|
+
getPoolForNamespace(indyNamespace: string): IndyVdrPool;
|
|
50
|
+
private getDidFromPool;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { CachedDidResponse, IndyVdrPoolService };
|
|
54
|
+
//# sourceMappingURL=IndyVdrPoolService.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndyVdrPoolService.d.mts","names":[],"sources":["../../src/pool/IndyVdrPoolService.ts"],"sourcesContent":[],"mappings":";;;;;;UAYiB,iBAAA;EAAA,WAAA,EAAA;IAQJ,GAAA,EAAA,MAAA;IACG,MAAA,EAAA,MAAA;EAI8C,CAAA;EAA6B,aAAA,EAAA,MAAA;;AAoBtE,cAzBR,kBAAA,CAyBQ;EAA2B,KAAA,EAxBhC,WAwBgC,EAAA;EAA3C,QAAA,MAAA;EA0G0B,QAAA,mBAAA;EAAA,WAAA,CAAA,MAAA,EA9H+B,MA8H/B,EAAA,mBAAA,EA9H4D,mBA8H5D;EAAA;;;;;;;;;;8BA5Gb,4BAEb;UAAgB;kBAA2B;;;;;;;4BA0GjB,QAAA;;;;4BAOA,QAAA;YAPA;;;;;;8CAkBmB"}
|