@ayanworks/credo-polygon-w3c-module 2.0.1 → 2.0.2-alpha-20260313061926

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.
@@ -1,6 +1,7 @@
1
1
  import { CreateSchemaOperationOptions, DidOperationOptions, PolygonLedgerService } from "./ledger/PolygonLedgerService.mjs";
2
2
  import "./ledger/index.mjs";
3
3
  import { AgentContext } from "@credo-ts/core";
4
+ import * as _ayanworks_polygon_schema_manager0 from "@ayanworks/polygon-schema-manager";
4
5
 
5
6
  //#region src/PolygonApi.d.ts
6
7
  declare class PolygonApi {
@@ -36,16 +37,7 @@ declare class PolygonApi {
36
37
  resourceTxnHash?: undefined;
37
38
  }>;
38
39
  getSchemaById(did: string, schemaId: string): Promise<any>;
39
- estimateFeeForDidOperation(options: DidOperationOptions): Promise<{
40
- transactionFee: string;
41
- gasLimit: string;
42
- gasPrice: string;
43
- maxFeePerGas: number;
44
- maxPriorityFeePerGas: number;
45
- network: string;
46
- chainId: string;
47
- method: string;
48
- } | null | undefined>;
40
+ estimateFeeForDidOperation(options: DidOperationOptions): Promise<_ayanworks_polygon_schema_manager0.EstimatedTxDetails | null>;
49
41
  estimateFeeForSchemaOperation(options: CreateSchemaOperationOptions): Promise<{} | undefined>;
50
42
  }
51
43
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"PolygonApi.d.mts","names":[],"sources":["../src/PolygonApi.ts"],"mappings":";;;;;cAMa,UAAA;EAAA,QACH,YAAA;EAAA,QACA,aAAA;cAGgB,YAAA,EAAc,YAAA,EACN,aAAA,EAAe,oBAAA;EAMlC,YAAA,CAAA;IAAe,GAAA;IAAK,UAAA;IAAY;EAAA;IAAY,GAAA;IAAa,UAAA;IAAoB,MAAA;EAAA,IAAgB,OAAA;;;;;;;;;;;;;;;;;;;;EAK7F,aAAA,CAAc,GAAA,UAAa,QAAA,WAAgB,OAAA;EAK3C,0BAAA,CAA2B,OAAA,EAAS,mBAAA,GAAmB,OAAA;;;;;;;;;;EAKvD,6BAAA,CAA8B,OAAA,EAAS,4BAAA,GAA4B,OAAA;AAAA"}
1
+ {"version":3,"file":"PolygonApi.d.mts","names":[],"sources":["../src/PolygonApi.ts"],"mappings":";;;;;;cAMa,UAAA;EAAA,QACH,YAAA;EAAA,QACA,aAAA;cAGgB,YAAA,EAAc,YAAA,EACN,aAAA,EAAe,oBAAA;EAMlC,YAAA,CAAA;IAAe,GAAA;IAAK,UAAA;IAAY;EAAA;IAAY,GAAA;IAAa,UAAA;IAAoB,MAAA;EAAA,IAAgB,OAAA;;;;;;;;;;;;;;;;;;;;EAK7F,aAAA,CAAc,GAAA,UAAa,QAAA,WAAgB,OAAA;EAK3C,0BAAA,CAA2B,OAAA,EAAS,mBAAA,GAAmB,OAAA,CAAA,kCAAA,CAAA,kBAAA;EAKvD,6BAAA,CAA8B,OAAA,EAAS,4BAAA,GAA4B,OAAA;AAAA"}
@@ -1,6 +1,6 @@
1
1
  import { EcdsaSecp256k1Signature2019 } from "./signature-suites/EcdsaSecp256k1Signature2019.mjs";
2
- import { PolygonModuleConfig } from "./PolygonModuleConfig.mjs";
3
2
  import "./signature-suites/index.mjs";
3
+ import { PolygonModuleConfig } from "./PolygonModuleConfig.mjs";
4
4
  import { PolygonLedgerService } from "./ledger/PolygonLedgerService.mjs";
5
5
  import "./ledger/index.mjs";
6
6
  import { PolygonApi } from "./PolygonApi.mjs";
@@ -3,7 +3,7 @@ import { AgentContext, DidCreateOptions, DidCreateResult, DidDeactivateOptions,
3
3
  //#region src/dids/PolygonDidRegistrar.d.ts
4
4
  declare class PolygonDidRegistrar implements DidRegistrar {
5
5
  readonly supportedMethods: string[];
6
- private resolver;
6
+ private resolver?;
7
7
  /**
8
8
  * Import a private key to KMS with idempotency check
9
9
  * Uses base58 public key as keyId for backward compatibility
@@ -14,6 +14,7 @@ declare class PolygonDidRegistrar implements DidRegistrar {
14
14
  deactivate(agentContext: AgentContext, options: DidDeactivateOptions): Promise<DidDeactivateResult>;
15
15
  private getSigningKey;
16
16
  private getPublicKeyFromDid;
17
+ private _getResolver;
17
18
  }
18
19
  interface PolygonDidCreateOptions extends DidCreateOptions {
19
20
  method: 'polygon';
@@ -1 +1 @@
1
- {"version":3,"file":"PolygonDidRegistrar.d.mts","names":[],"sources":["../../src/dids/PolygonDidRegistrar.ts"],"mappings":";;;cA6Ba,mBAAA,YAA+B,YAAA;EAAA,SAC1B,gBAAA;EAAA,QACR,QAAA;EAFuB;;;;EAAA,QAQjB,cAAA;EA2CD,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,OAAA,EAAS,uBAAA,GAA0B,OAAA,CAAQ,eAAA;EAsF9E,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,OAAA,EAAS,uBAAA,GAA0B,OAAA,CAAQ,eAAA;EA2H9E,UAAA,CAAW,YAAA,EAAc,YAAA,EAAc,OAAA,EAAS,oBAAA,GAAuB,OAAA,CAAQ,mBAAA;EAAA,QAqE9E,aAAA;EAAA,QAmBA,mBAAA;AAAA;AAAA,UAkBC,uBAAA,SAAgC,gBAAA;EAC/C,MAAA;EACA,GAAA;EACA,OAAA;IACE,OAAA;IACA,QAAA;EAAA;EAEF,MAAA;IACE,UAAA,EAAY,UAAA;EAAA;AAAA;AAAA,UAIC,uBAAA,SAAgC,gBAAA;EAC/C,MAAA;EACA,GAAA;EACA,WAAA,EAAa,WAAA;EACb,MAAA;IACE,UAAA,EAAY,UAAA;EAAA;AAAA"}
1
+ {"version":3,"file":"PolygonDidRegistrar.d.mts","names":[],"sources":["../../src/dids/PolygonDidRegistrar.ts"],"mappings":";;;cA8Ba,mBAAA,YAA+B,YAAA;EAAA,SAC1B,gBAAA;EAAA,QACR,QAAA;EAFuB;;;;EAAA,QAQjB,cAAA;EA2CD,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,OAAA,EAAS,uBAAA,GAA0B,OAAA,CAAQ,eAAA;EA4F9E,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,OAAA,EAAS,uBAAA,GAA0B,OAAA,CAAQ,eAAA;EA2H9E,UAAA,CAAW,YAAA,EAAc,YAAA,EAAc,OAAA,EAAS,oBAAA,GAAuB,OAAA,CAAQ,mBAAA;EAAA,QAqE9E,aAAA;EAAA,QAmBA,mBAAA;EAAA,QAiBN,YAAA;AAAA;AAAA,UAWO,uBAAA,SAAgC,gBAAA;EAC/C,MAAA;EACA,GAAA;EACA,OAAA;IACE,OAAA;IACA,QAAA;EAAA;EAEF,MAAA;IACE,UAAA,EAAY,UAAA;EAAA;AAAA;AAAA,UAIC,uBAAA,SAAgC,gBAAA;EAC/C,MAAA;EACA,GAAA;EACA,WAAA,EAAa,WAAA;EACb,MAAA;IACE,UAAA,EAAY,UAAA;EAAA;AAAA"}
@@ -1,7 +1,10 @@
1
+ import { getCompressedEcdsaSecp256k1VerificationKey2019 } from "../utils/utils.mjs";
2
+ import "../utils/index.mjs";
1
3
  import { buildDid, createSecp256k1PublicJwk, getSecp256k1DidDoc, validateSpecCompliantPayload } from "./didPolygonUtil.mjs";
4
+ import { PolygonModuleConfig } from "../PolygonModuleConfig.mjs";
2
5
  import { PolygonLedgerService } from "../ledger/PolygonLedgerService.mjs";
3
6
  import "../ledger/index.mjs";
4
- import { Buffer, CredoError, DidDocument, DidDocumentBuilder, DidDocumentRole, DidRecord, DidRepository, JsonTransformer, TypedArrayEncoder, getEcdsaSecp256k1VerificationKey2019 } from "@credo-ts/core";
7
+ import { Buffer, CredoError, DidDocument, DidDocumentBuilder, DidDocumentRole, DidRecord, DidRepository, JsonTransformer, TypedArrayEncoder } from "@credo-ts/core";
5
8
  import { KeyManagementApi, KeyManagementKeyNotFoundError } from "@credo-ts/core/kms";
6
9
  import { JsonRpcProvider, SigningKey, Wallet } from "ethers";
7
10
  import { getResolver } from "@ayanworks/polygon-did-resolver";
@@ -12,7 +15,6 @@ import { Resolver } from "did-resolver";
12
15
  var PolygonDidRegistrar = class {
13
16
  constructor() {
14
17
  this.supportedMethods = ["polygon"];
15
- this.resolver = new Resolver(getResolver());
16
18
  }
17
19
  /**
18
20
  * Import a private key to KMS with idempotency check
@@ -64,7 +66,7 @@ var PolygonDidRegistrar = class {
64
66
  reason: "Insufficient balance in wallet"
65
67
  }
66
68
  };
67
- const { publicKeyBase58, publicJwk } = await this.importKeyToKms(agentContext, privateKey);
69
+ const { publicKeyBase58, publicJwk, keyId } = await this.importKeyToKms(agentContext, privateKey);
68
70
  const ecPublicJwk = publicJwk;
69
71
  const fullPublicKeyHex = Buffer.from(ecPublicJwk.x, "base64url").toString("hex") + Buffer.from(ecPublicJwk.y, "base64url").toString("hex");
70
72
  const did = buildDid(options.method, options.options.network, fullPublicKeyHex);
@@ -80,7 +82,11 @@ var PolygonDidRegistrar = class {
80
82
  const didRecord = new DidRecord({
81
83
  did: didDocument.id,
82
84
  role: DidDocumentRole.Created,
83
- didDocument
85
+ didDocument,
86
+ keys: [{
87
+ kmsKeyId: keyId,
88
+ didDocumentRelativeKeyId: `${didDocument.id}#key-1`
89
+ }]
84
90
  });
85
91
  agentContext.config.logger.info(`Saving DID record to wallet: ${did} and did document: ${didDocument}`);
86
92
  await didRepository.save(agentContext, didRecord);
@@ -115,7 +121,7 @@ var PolygonDidRegistrar = class {
115
121
  const isValidDidDoc = validateSpecCompliantPayload(options.didDocument);
116
122
  if (options.didDocument && isValidDidDoc === null) {
117
123
  didDocument = options.didDocument;
118
- const resolvedDocument = await this.resolver.resolve(didDocument.id);
124
+ const resolvedDocument = await this._getResolver(agentContext).resolve(didDocument.id);
119
125
  didRecord = await didRepository.findCreatedDid(agentContext, didDocument.id);
120
126
  if (!resolvedDocument.didDocument || resolvedDocument.didDocumentMetadata.deactivated || !didRecord) return {
121
127
  didDocumentMetadata: {},
@@ -142,7 +148,7 @@ var PolygonDidRegistrar = class {
142
148
  const { publicKeyBase58: _, publicJwk } = await this.importKeyToKms(agentContext, privateKey);
143
149
  const verificationMethodCount = didDocument?.verificationMethod?.length ?? 0;
144
150
  const secp256k1Jwk = createSecp256k1PublicJwk(publicJwk);
145
- const verificationMethod = getEcdsaSecp256k1VerificationKey2019({
151
+ const verificationMethod = getCompressedEcdsaSecp256k1VerificationKey2019({
146
152
  id: `${didDocument.id}#key-${verificationMethodCount + 1}`,
147
153
  publicJwk: secp256k1Jwk,
148
154
  controller: didDocument.id
@@ -199,7 +205,7 @@ var PolygonDidRegistrar = class {
199
205
  const ledgerService = agentContext.dependencyManager.resolve(PolygonLedgerService);
200
206
  const did = options.did;
201
207
  try {
202
- const { didDocument, didDocumentMetadata } = await this.resolver.resolve(did);
208
+ const { didDocument, didDocumentMetadata } = await this._getResolver(agentContext).resolve(did);
203
209
  const didRecord = await didRepository.findCreatedDid(agentContext, did);
204
210
  if (!didDocument || didDocumentMetadata.deactivated || !didRecord) return {
205
211
  didDocumentMetadata: {},
@@ -253,6 +259,13 @@ var PolygonDidRegistrar = class {
253
259
  if (!didRecord.didDocument?.verificationMethod) throw new CredoError("VerificationMethod not found cannot get public key");
254
260
  return didRecord.didDocument.verificationMethod[0].publicKeyBase58;
255
261
  }
262
+ _getResolver(agentContext) {
263
+ if (!this.resolver) {
264
+ const polygonOptions = agentContext.dependencyManager.resolve(PolygonModuleConfig);
265
+ this.resolver = new Resolver(getResolver(polygonOptions.rpcUrl, polygonOptions.didContractAddress));
266
+ }
267
+ return this.resolver;
268
+ }
256
269
  };
257
270
 
258
271
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"PolygonDidRegistrar.mjs","names":["EtherWallet"],"sources":["../../src/dids/PolygonDidRegistrar.ts"],"sourcesContent":["import { getResolver } from '@ayanworks/polygon-did-resolver'\nimport { AskarStoreManager, transformPrivateKeyToPrivateJwk } from '@credo-ts/askar'\nimport {\n type AgentContext,\n Buffer,\n CredoError,\n type DidCreateOptions,\n type DidCreateResult,\n type DidDeactivateOptions,\n type DidDeactivateResult,\n DidDocument,\n DidDocumentBuilder,\n DidDocumentRole,\n DidRecord,\n type DidRegistrar,\n DidRepository,\n type DidUpdateOptions,\n type DidUpdateResult,\n getEcdsaSecp256k1VerificationKey2019,\n JsonTransformer,\n TypedArrayEncoder,\n} from '@credo-ts/core'\nimport type { KmsJwkPublic } from '@credo-ts/core/kms'\nimport { KeyManagementApi, KeyManagementKeyNotFoundError } from '@credo-ts/core/kms'\nimport { Resolver } from 'did-resolver'\nimport { Wallet as EtherWallet, JsonRpcProvider, SigningKey } from 'ethers'\nimport { PolygonLedgerService } from '../ledger'\nimport { buildDid, createSecp256k1PublicJwk, getSecp256k1DidDoc, validateSpecCompliantPayload } from './didPolygonUtil'\n\nexport class PolygonDidRegistrar implements DidRegistrar {\n public readonly supportedMethods = ['polygon']\n private resolver = new Resolver(getResolver())\n\n /**\n * Import a private key to KMS with idempotency check\n * Uses base58 public key as keyId for backward compatibility\n */\n private async importKeyToKms(\n agentContext: AgentContext,\n privateKey: Uint8Array\n ): Promise<{ publicKeyBase58: string; publicJwk: KmsJwkPublic; keyId: string }> {\n const kmsApi = agentContext.dependencyManager.resolve(KeyManagementApi)\n\n // Calculate base58 public key for kid\n const signingKey = new SigningKey(privateKey)\n const publicKeyHex = signingKey.compressedPublicKey.substring(2) // Remove '0x' prefix\n const publicKeyBuffer = Buffer.from(publicKeyHex, 'hex')\n const publicKeyBase58 = TypedArrayEncoder.toBase58(publicKeyBuffer)\n\n // Transform to JWK\n const { privateJwk } = transformPrivateKeyToPrivateJwk({\n type: { kty: 'EC', crv: 'secp256k1' },\n privateKey: privateKey,\n })\n privateJwk.kid = publicKeyBase58\n\n // Check if key already exists\n let publicJwk: any\n try {\n publicJwk = await kmsApi.getPublicKey({ keyId: publicKeyBase58 })\n } catch (error) {\n if (error instanceof KeyManagementKeyNotFoundError) {\n agentContext.config.logger.debug(`Key not found in wallet: ${error}`)\n }\n }\n let keyId = publicKeyBase58\n\n if (!publicJwk) {\n // Import new key\n const importedKey = await kmsApi.importKey({ privateJwk })\n publicJwk = importedKey.publicJwk\n keyId = importedKey.keyId\n agentContext.config.logger.debug(`Imported new key to KMS: ${keyId}`)\n } else {\n agentContext.config.logger.debug(`Key already exists in KMS: ${keyId}`)\n }\n\n return { publicKeyBase58, publicJwk, keyId }\n }\n\n public async create(agentContext: AgentContext, options: PolygonDidCreateOptions): Promise<DidCreateResult> {\n const ledgerService = agentContext.dependencyManager.resolve(PolygonLedgerService)\n const didRepository = agentContext.dependencyManager.resolve(DidRepository)\n\n const privateKey = options.secret.privateKey\n\n // Check balance using ethers wallet\n const signingKey = new SigningKey(privateKey)\n const wallet = new EtherWallet(signingKey)\n const provider = new JsonRpcProvider(ledgerService.rpcUrl)\n const value = await provider.getBalance(wallet.address)\n\n if (Number(value) === 0) {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: 'Insufficient balance in wallet',\n },\n }\n }\n\n // Import key to KMS with base58 keyId\n const { publicKeyBase58, publicJwk } = await this.importKeyToKms(agentContext, privateKey)\n\n // Build DID from public key coordinates (we know it's EC with secp256k1)\n const ecPublicJwk = publicJwk as { x: string; y: string }\n const xHex = Buffer.from(ecPublicJwk.x, 'base64url').toString('hex')\n const yHex = Buffer.from(ecPublicJwk.y, 'base64url').toString('hex')\n const fullPublicKeyHex = xHex + yHex\n const did = buildDid(options.method, options.options.network, fullPublicKeyHex)\n\n agentContext.config.logger.info(`Creating DID on ledger: ${did}`)\n\n try {\n const signingKey = await this.getSigningKey(agentContext, publicKeyBase58)\n\n const didRegistry = ledgerService.createDidRegistryInstance(signingKey)\n\n // Create DID document with PublicJwk\n const secp256k1Jwk = createSecp256k1PublicJwk(ecPublicJwk)\n const secpDidDoc = getSecp256k1DidDoc(did, secp256k1Jwk as any, options.options.endpoint)\n\n const response = await didRegistry.create(did, secpDidDoc as any)\n\n agentContext.config.logger.info(`Published did on ledger: ${did}`)\n\n const didDoc = response.didDoc\n const didDocument = JsonTransformer.fromJSON(didDoc, DidDocument)\n\n const didRecord = new DidRecord({\n did: didDocument.id,\n role: DidDocumentRole.Created,\n didDocument,\n })\n\n agentContext.config.logger.info(`Saving DID record to wallet: ${did} and did document: ${didDocument}`)\n\n await didRepository.save(agentContext, didRecord)\n\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {\n txn: response.txnHash,\n },\n didState: {\n state: 'finished',\n did: didDocument.id,\n didDocument: didDocument,\n },\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n agentContext.config.logger.error(`Error registering DID ${did} : ${errorMessage}`)\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: `unknownError: ${errorMessage}`,\n },\n }\n }\n }\n\n public async update(agentContext: AgentContext, options: PolygonDidUpdateOptions): Promise<DidUpdateResult> {\n const ledgerService = agentContext.dependencyManager.resolve(PolygonLedgerService)\n const didRepository = agentContext.dependencyManager.resolve(DidRepository)\n\n let didDocument: DidDocument\n let didRecord: DidRecord | null\n\n try {\n const isValidDidDoc = validateSpecCompliantPayload(options.didDocument)\n if (options.didDocument && isValidDidDoc === null) {\n didDocument = options.didDocument\n const resolvedDocument = await this.resolver.resolve(didDocument.id)\n didRecord = await didRepository.findCreatedDid(agentContext, didDocument.id)\n if (!resolvedDocument.didDocument || resolvedDocument.didDocumentMetadata.deactivated || !didRecord) {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: 'Did not found',\n },\n }\n }\n\n if (options?.secret?.privateKey) {\n const privateKey = options.secret.privateKey\n\n // Validate private key\n try {\n new SigningKey(privateKey)\n } catch {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: 'Invalid private key provided',\n },\n }\n }\n\n // Import key to KMS with base58 keyId\n const { publicKeyBase58: _, publicJwk } = await this.importKeyToKms(agentContext, privateKey)\n\n // Create verification method using publicJwk\n const verificationMethodCount = didDocument?.verificationMethod?.length ?? 0\n const ecPublicJwk = publicJwk as { x: string; y: string }\n const secp256k1Jwk = createSecp256k1PublicJwk(ecPublicJwk)\n const verificationMethod = getEcdsaSecp256k1VerificationKey2019({\n id: `${didDocument.id}#key-${verificationMethodCount + 1}`,\n publicJwk: secp256k1Jwk as any,\n controller: didDocument.id,\n })\n\n didDocument.verificationMethod = [...(didDocument?.verificationMethod ?? []), verificationMethod]\n }\n } else {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: isValidDidDoc ?? 'Provide a valid didDocument',\n },\n }\n }\n\n if (!didRecord) {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: 'DidRecord not found in wallet',\n },\n }\n }\n\n const publicKeyBase58 = await this.getPublicKeyFromDid(agentContext, options.did)\n\n if (!publicKeyBase58) {\n throw new CredoError('Public Key not found in wallet')\n }\n\n const signingKey = await this.getSigningKey(agentContext, publicKeyBase58)\n\n const didRegistry = ledgerService.createDidRegistryInstance(signingKey)\n\n const response = await didRegistry.update(didDocument.id, didDocument as any)\n\n if (!response) {\n throw new Error('Unable to update did document')\n }\n\n // Save the did document\n didRecord.didDocument = didDocument\n await didRepository.update(agentContext, didRecord)\n\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {\n txn: response.txnHash,\n },\n didState: {\n state: 'finished',\n did: didDocument.id,\n didDocument,\n },\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n agentContext.config.logger.error(`Error Updating DID : ${errorMessage}`)\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: `unknownError: ${errorMessage}`,\n },\n }\n }\n }\n\n public async deactivate(agentContext: AgentContext, options: DidDeactivateOptions): Promise<DidDeactivateResult> {\n const didRepository = agentContext.dependencyManager.resolve(DidRepository)\n const ledgerService = agentContext.dependencyManager.resolve(PolygonLedgerService)\n\n const did = options.did\n\n try {\n const { didDocument, didDocumentMetadata } = await this.resolver.resolve(did)\n\n const didRecord = await didRepository.findCreatedDid(agentContext, did)\n if (!didDocument || didDocumentMetadata.deactivated || !didRecord) {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: 'Did not found',\n },\n }\n }\n\n const publicKeyBase58 = await this.getPublicKeyFromDid(agentContext, options.did)\n\n if (!publicKeyBase58) {\n throw new CredoError('Public Key not found in wallet')\n }\n\n const signingKey = await this.getSigningKey(agentContext, publicKeyBase58)\n\n const didRegistry = ledgerService.createDidRegistryInstance(signingKey)\n\n const updatedDidDocument = new DidDocumentBuilder(options.did).addContext('https://www.w3.org/ns/did/v1').build()\n\n const response = await didRegistry.update(didDocument.id, updatedDidDocument as any)\n\n if (!response) {\n throw new CredoError(`Unable to deactivate did document for did : ${did}`)\n }\n\n await didRepository.update(agentContext, didRecord)\n\n return {\n didDocumentMetadata: {\n deactivated: true,\n },\n didRegistrationMetadata: {\n txn: response.txnHash,\n },\n didState: {\n state: 'finished',\n did: didDocument.id,\n didDocument: JsonTransformer.fromJSON(didDocument, DidDocument),\n secret: options.secret,\n },\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n agentContext.config.logger.error(`Error deactivating DID ${errorMessage}`)\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: `unknownError: ${errorMessage}`,\n },\n }\n }\n }\n\n private async getSigningKey(agentContext: AgentContext, publicKeyBase58: string): Promise<SigningKey> {\n const askarStoreManager = agentContext.dependencyManager.resolve(AskarStoreManager)\n\n const keyEntry = await askarStoreManager.withSession(\n agentContext,\n async (session) => await session.fetchKey({ name: publicKeyBase58 })\n )\n\n if (!keyEntry) {\n throw new CredoError('Key not found in wallet')\n }\n\n const signingKey = new SigningKey(keyEntry.key.secretBytes)\n\n keyEntry.key.handle.free()\n\n return signingKey\n }\n\n private async getPublicKeyFromDid(agentContext: AgentContext, did: string) {\n const didRepository = agentContext.dependencyManager.resolve(DidRepository)\n\n const didRecord = await didRepository.findCreatedDid(agentContext, did)\n if (!didRecord) {\n throw new CredoError('DidRecord not found')\n }\n\n if (!didRecord.didDocument?.verificationMethod) {\n throw new CredoError('VerificationMethod not found cannot get public key')\n }\n\n const publicKeyBase58 = didRecord.didDocument.verificationMethod[0].publicKeyBase58\n\n return publicKeyBase58\n }\n}\n\nexport interface PolygonDidCreateOptions extends DidCreateOptions {\n method: 'polygon'\n did?: never\n options: {\n network: 'mainnet' | 'testnet'\n endpoint?: string\n }\n secret: {\n privateKey: Uint8Array\n }\n}\n\nexport interface PolygonDidUpdateOptions extends DidUpdateOptions {\n method: 'polygon'\n did: string\n didDocument: DidDocument\n secret?: {\n privateKey: Uint8Array\n }\n}\n"],"mappings":";;;;;;;;;;;AA6BA,IAAa,sBAAb,MAAyD;;OACvC,mBAAmB,CAAC,UAAU;OACtC,WAAW,IAAI,SAAS,aAAa,CAAC;;;;;;CAM9C,MAAc,eACZ,cACA,YAC8E;EAC9E,MAAM,SAAS,aAAa,kBAAkB,QAAQ,iBAAiB;EAIvE,MAAM,eADa,IAAI,WAAW,WAAW,CACb,oBAAoB,UAAU,EAAE;EAChE,MAAM,kBAAkB,OAAO,KAAK,cAAc,MAAM;EACxD,MAAM,kBAAkB,kBAAkB,SAAS,gBAAgB;EAGnE,MAAM,EAAE,eAAe,gCAAgC;GACrD,MAAM;IAAE,KAAK;IAAM,KAAK;IAAa;GACzB;GACb,CAAC;AACF,aAAW,MAAM;EAGjB,IAAI;AACJ,MAAI;AACF,eAAY,MAAM,OAAO,aAAa,EAAE,OAAO,iBAAiB,CAAC;WAC1D,OAAO;AACd,OAAI,iBAAiB,8BACnB,cAAa,OAAO,OAAO,MAAM,4BAA4B,QAAQ;;EAGzE,IAAI,QAAQ;AAEZ,MAAI,CAAC,WAAW;GAEd,MAAM,cAAc,MAAM,OAAO,UAAU,EAAE,YAAY,CAAC;AAC1D,eAAY,YAAY;AACxB,WAAQ,YAAY;AACpB,gBAAa,OAAO,OAAO,MAAM,4BAA4B,QAAQ;QAErE,cAAa,OAAO,OAAO,MAAM,8BAA8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,cAAc,cAA4B,iBAA8C;EAGpG,MAAM,WAAW,MAFS,aAAa,kBAAkB,QAAQ,kBAAkB,CAE1C,YACvC,cACA,OAAO,YAAY,MAAM,QAAQ,SAAS,EAAE,MAAM,iBAAiB,CAAC,CACrE;AAED,MAAI,CAAC,SACH,OAAM,IAAI,WAAW,0BAA0B;EAGjD,MAAM,aAAa,IAAI,WAAW,SAAS,IAAI,YAAY;AAE3D,WAAS,IAAI,OAAO,MAAM;AAE1B,SAAO;;CAGT,MAAc,oBAAoB,cAA4B,KAAa;EAGzE,MAAM,YAAY,MAFI,aAAa,kBAAkB,QAAQ,cAAc,CAErC,eAAe,cAAc,IAAI;AACvE,MAAI,CAAC,UACH,OAAM,IAAI,WAAW,sBAAsB;AAG7C,MAAI,CAAC,UAAU,aAAa,mBAC1B,OAAM,IAAI,WAAW,qDAAqD;AAK5E,SAFwB,UAAU,YAAY,mBAAmB,GAAG"}
1
+ {"version":3,"file":"PolygonDidRegistrar.mjs","names":["EtherWallet"],"sources":["../../src/dids/PolygonDidRegistrar.ts"],"sourcesContent":["import { getResolver } from '@ayanworks/polygon-did-resolver'\nimport { AskarStoreManager, transformPrivateKeyToPrivateJwk } from '@credo-ts/askar'\nimport {\n type AgentContext,\n Buffer,\n CredoError,\n type DidCreateOptions,\n type DidCreateResult,\n type DidDeactivateOptions,\n type DidDeactivateResult,\n DidDocument,\n DidDocumentBuilder,\n DidDocumentRole,\n DidRecord,\n type DidRegistrar,\n DidRepository,\n type DidUpdateOptions,\n type DidUpdateResult,\n JsonTransformer,\n TypedArrayEncoder,\n} from '@credo-ts/core'\nimport type { KmsJwkPublic } from '@credo-ts/core/kms'\nimport { KeyManagementApi, KeyManagementKeyNotFoundError } from '@credo-ts/core/kms'\nimport { Resolver } from 'did-resolver'\nimport { Wallet as EtherWallet, JsonRpcProvider, SigningKey } from 'ethers'\nimport { PolygonLedgerService } from '../ledger'\nimport { PolygonModuleConfig } from '../PolygonModuleConfig'\nimport { getCompressedEcdsaSecp256k1VerificationKey2019 } from '../utils'\nimport { buildDid, createSecp256k1PublicJwk, getSecp256k1DidDoc, validateSpecCompliantPayload } from './didPolygonUtil'\n\nexport class PolygonDidRegistrar implements DidRegistrar {\n public readonly supportedMethods = ['polygon']\n private resolver?: Resolver\n\n /**\n * Import a private key to KMS with idempotency check\n * Uses base58 public key as keyId for backward compatibility\n */\n private async importKeyToKms(\n agentContext: AgentContext,\n privateKey: Uint8Array\n ): Promise<{ publicKeyBase58: string; publicJwk: KmsJwkPublic; keyId: string }> {\n const kmsApi = agentContext.dependencyManager.resolve(KeyManagementApi)\n\n // Calculate base58 public key for kid\n const signingKey = new SigningKey(privateKey)\n const publicKeyHex = signingKey.compressedPublicKey.substring(2) // Remove '0x' prefix\n const publicKeyBuffer = Buffer.from(publicKeyHex, 'hex')\n const publicKeyBase58 = TypedArrayEncoder.toBase58(publicKeyBuffer)\n\n // Transform to JWK\n const { privateJwk } = transformPrivateKeyToPrivateJwk({\n type: { kty: 'EC', crv: 'secp256k1' },\n privateKey: privateKey,\n })\n privateJwk.kid = publicKeyBase58\n\n // Check if key already exists\n let publicJwk: any\n try {\n publicJwk = await kmsApi.getPublicKey({ keyId: publicKeyBase58 })\n } catch (error) {\n if (error instanceof KeyManagementKeyNotFoundError) {\n agentContext.config.logger.debug(`Key not found in wallet: ${error}`)\n }\n }\n let keyId = publicKeyBase58\n\n if (!publicJwk) {\n // Import new key\n const importedKey = await kmsApi.importKey({ privateJwk })\n publicJwk = importedKey.publicJwk\n keyId = importedKey.keyId\n agentContext.config.logger.debug(`Imported new key to KMS: ${keyId}`)\n } else {\n agentContext.config.logger.debug(`Key already exists in KMS: ${keyId}`)\n }\n\n return { publicKeyBase58, publicJwk, keyId }\n }\n\n public async create(agentContext: AgentContext, options: PolygonDidCreateOptions): Promise<DidCreateResult> {\n const ledgerService = agentContext.dependencyManager.resolve(PolygonLedgerService)\n const didRepository = agentContext.dependencyManager.resolve(DidRepository)\n\n const privateKey = options.secret.privateKey\n\n // Check balance using ethers wallet\n const signingKey = new SigningKey(privateKey)\n const wallet = new EtherWallet(signingKey)\n const provider = new JsonRpcProvider(ledgerService.rpcUrl)\n const value = await provider.getBalance(wallet.address)\n\n if (Number(value) === 0) {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: 'Insufficient balance in wallet',\n },\n }\n }\n\n // Import key to KMS with base58 keyId\n const { publicKeyBase58, publicJwk, keyId } = await this.importKeyToKms(agentContext, privateKey)\n\n // Build DID from public key coordinates (we know it's EC with secp256k1)\n const ecPublicJwk = publicJwk as { x: string; y: string }\n const xHex = Buffer.from(ecPublicJwk.x, 'base64url').toString('hex')\n const yHex = Buffer.from(ecPublicJwk.y, 'base64url').toString('hex')\n const fullPublicKeyHex = xHex + yHex\n const did = buildDid(options.method, options.options.network, fullPublicKeyHex)\n\n agentContext.config.logger.info(`Creating DID on ledger: ${did}`)\n\n try {\n const signingKey = await this.getSigningKey(agentContext, publicKeyBase58)\n\n const didRegistry = ledgerService.createDidRegistryInstance(signingKey)\n\n // Create DID document with PublicJwk\n const secp256k1Jwk = createSecp256k1PublicJwk(ecPublicJwk)\n const secpDidDoc = getSecp256k1DidDoc(did, secp256k1Jwk as any, options.options.endpoint)\n\n const response = await didRegistry.create(did, secpDidDoc as any)\n\n agentContext.config.logger.info(`Published did on ledger: ${did}`)\n\n const didDoc = response.didDoc\n const didDocument = JsonTransformer.fromJSON(didDoc, DidDocument)\n\n const didRecord = new DidRecord({\n did: didDocument.id,\n role: DidDocumentRole.Created,\n didDocument,\n keys: [\n {\n kmsKeyId: keyId,\n didDocumentRelativeKeyId: `${didDocument.id}#key-1`,\n },\n ],\n })\n\n agentContext.config.logger.info(`Saving DID record to wallet: ${did} and did document: ${didDocument}`)\n\n await didRepository.save(agentContext, didRecord)\n\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {\n txn: response.txnHash,\n },\n didState: {\n state: 'finished',\n did: didDocument.id,\n didDocument: didDocument,\n },\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n agentContext.config.logger.error(`Error registering DID ${did} : ${errorMessage}`)\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: `unknownError: ${errorMessage}`,\n },\n }\n }\n }\n\n public async update(agentContext: AgentContext, options: PolygonDidUpdateOptions): Promise<DidUpdateResult> {\n const ledgerService = agentContext.dependencyManager.resolve(PolygonLedgerService)\n const didRepository = agentContext.dependencyManager.resolve(DidRepository)\n\n let didDocument: DidDocument\n let didRecord: DidRecord | null\n\n try {\n const isValidDidDoc = validateSpecCompliantPayload(options.didDocument)\n if (options.didDocument && isValidDidDoc === null) {\n didDocument = options.didDocument\n const resolvedDocument = await this._getResolver(agentContext).resolve(didDocument.id)\n didRecord = await didRepository.findCreatedDid(agentContext, didDocument.id)\n if (!resolvedDocument.didDocument || resolvedDocument.didDocumentMetadata.deactivated || !didRecord) {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: 'Did not found',\n },\n }\n }\n\n if (options?.secret?.privateKey) {\n const privateKey = options.secret.privateKey\n\n // Validate private key\n try {\n new SigningKey(privateKey)\n } catch {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: 'Invalid private key provided',\n },\n }\n }\n\n // Import key to KMS with base58 keyId\n const { publicKeyBase58: _, publicJwk } = await this.importKeyToKms(agentContext, privateKey)\n\n // Create verification method using publicJwk\n const verificationMethodCount = didDocument?.verificationMethod?.length ?? 0\n const ecPublicJwk = publicJwk as { x: string; y: string }\n const secp256k1Jwk = createSecp256k1PublicJwk(ecPublicJwk)\n const verificationMethod = getCompressedEcdsaSecp256k1VerificationKey2019({\n id: `${didDocument.id}#key-${verificationMethodCount + 1}`,\n publicJwk: secp256k1Jwk as any,\n controller: didDocument.id,\n })\n\n didDocument.verificationMethod = [...(didDocument?.verificationMethod ?? []), verificationMethod]\n }\n } else {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: isValidDidDoc ?? 'Provide a valid didDocument',\n },\n }\n }\n\n if (!didRecord) {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: 'DidRecord not found in wallet',\n },\n }\n }\n\n const publicKeyBase58 = await this.getPublicKeyFromDid(agentContext, options.did)\n\n if (!publicKeyBase58) {\n throw new CredoError('Public Key not found in wallet')\n }\n\n const signingKey = await this.getSigningKey(agentContext, publicKeyBase58)\n\n const didRegistry = ledgerService.createDidRegistryInstance(signingKey)\n\n const response = await didRegistry.update(didDocument.id, didDocument as any)\n\n if (!response) {\n throw new Error('Unable to update did document')\n }\n\n // Save the did document\n didRecord.didDocument = didDocument\n await didRepository.update(agentContext, didRecord)\n\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {\n txn: response.txnHash,\n },\n didState: {\n state: 'finished',\n did: didDocument.id,\n didDocument,\n },\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n agentContext.config.logger.error(`Error Updating DID : ${errorMessage}`)\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: `unknownError: ${errorMessage}`,\n },\n }\n }\n }\n\n public async deactivate(agentContext: AgentContext, options: DidDeactivateOptions): Promise<DidDeactivateResult> {\n const didRepository = agentContext.dependencyManager.resolve(DidRepository)\n const ledgerService = agentContext.dependencyManager.resolve(PolygonLedgerService)\n\n const did = options.did\n\n try {\n const { didDocument, didDocumentMetadata } = await this._getResolver(agentContext).resolve(did)\n\n const didRecord = await didRepository.findCreatedDid(agentContext, did)\n if (!didDocument || didDocumentMetadata.deactivated || !didRecord) {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: 'Did not found',\n },\n }\n }\n\n const publicKeyBase58 = await this.getPublicKeyFromDid(agentContext, options.did)\n\n if (!publicKeyBase58) {\n throw new CredoError('Public Key not found in wallet')\n }\n\n const signingKey = await this.getSigningKey(agentContext, publicKeyBase58)\n\n const didRegistry = ledgerService.createDidRegistryInstance(signingKey)\n\n const updatedDidDocument = new DidDocumentBuilder(options.did).addContext('https://www.w3.org/ns/did/v1').build()\n\n const response = await didRegistry.update(didDocument.id, updatedDidDocument as any)\n\n if (!response) {\n throw new CredoError(`Unable to deactivate did document for did : ${did}`)\n }\n\n await didRepository.update(agentContext, didRecord)\n\n return {\n didDocumentMetadata: {\n deactivated: true,\n },\n didRegistrationMetadata: {\n txn: response.txnHash,\n },\n didState: {\n state: 'finished',\n did: didDocument.id,\n didDocument: JsonTransformer.fromJSON(didDocument, DidDocument),\n secret: options.secret,\n },\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n agentContext.config.logger.error(`Error deactivating DID ${errorMessage}`)\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: `unknownError: ${errorMessage}`,\n },\n }\n }\n }\n\n private async getSigningKey(agentContext: AgentContext, publicKeyBase58: string): Promise<SigningKey> {\n const askarStoreManager = agentContext.dependencyManager.resolve(AskarStoreManager)\n\n const keyEntry = await askarStoreManager.withSession(\n agentContext,\n async (session) => await session.fetchKey({ name: publicKeyBase58 })\n )\n\n if (!keyEntry) {\n throw new CredoError('Key not found in wallet')\n }\n\n const signingKey = new SigningKey(keyEntry.key.secretBytes)\n\n keyEntry.key.handle.free()\n\n return signingKey\n }\n\n private async getPublicKeyFromDid(agentContext: AgentContext, did: string) {\n const didRepository = agentContext.dependencyManager.resolve(DidRepository)\n\n const didRecord = await didRepository.findCreatedDid(agentContext, did)\n if (!didRecord) {\n throw new CredoError('DidRecord not found')\n }\n\n if (!didRecord.didDocument?.verificationMethod) {\n throw new CredoError('VerificationMethod not found cannot get public key')\n }\n\n const publicKeyBase58 = didRecord.didDocument.verificationMethod[0].publicKeyBase58\n\n return publicKeyBase58\n }\n\n private _getResolver(agentContext: AgentContext): Resolver {\n if (!this.resolver) {\n const polygonOptions = agentContext.dependencyManager.resolve(PolygonModuleConfig)\n\n this.resolver = new Resolver(getResolver(polygonOptions.rpcUrl, polygonOptions.didContractAddress))\n }\n\n return this.resolver\n }\n}\n\nexport interface PolygonDidCreateOptions extends DidCreateOptions {\n method: 'polygon'\n did?: never\n options: {\n network: 'mainnet' | 'testnet'\n endpoint?: string\n }\n secret: {\n privateKey: Uint8Array\n }\n}\n\nexport interface PolygonDidUpdateOptions extends DidUpdateOptions {\n method: 'polygon'\n did: string\n didDocument: DidDocument\n secret?: {\n privateKey: Uint8Array\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA8BA,IAAa,sBAAb,MAAyD;;OACvC,mBAAmB,CAAC,UAAU;;;;;;CAO9C,MAAc,eACZ,cACA,YAC8E;EAC9E,MAAM,SAAS,aAAa,kBAAkB,QAAQ,iBAAiB;EAIvE,MAAM,eADa,IAAI,WAAW,WAAW,CACb,oBAAoB,UAAU,EAAE;EAChE,MAAM,kBAAkB,OAAO,KAAK,cAAc,MAAM;EACxD,MAAM,kBAAkB,kBAAkB,SAAS,gBAAgB;EAGnE,MAAM,EAAE,eAAe,gCAAgC;GACrD,MAAM;IAAE,KAAK;IAAM,KAAK;IAAa;GACzB;GACb,CAAC;AACF,aAAW,MAAM;EAGjB,IAAI;AACJ,MAAI;AACF,eAAY,MAAM,OAAO,aAAa,EAAE,OAAO,iBAAiB,CAAC;WAC1D,OAAO;AACd,OAAI,iBAAiB,8BACnB,cAAa,OAAO,OAAO,MAAM,4BAA4B,QAAQ;;EAGzE,IAAI,QAAQ;AAEZ,MAAI,CAAC,WAAW;GAEd,MAAM,cAAc,MAAM,OAAO,UAAU,EAAE,YAAY,CAAC;AAC1D,eAAY,YAAY;AACxB,WAAQ,YAAY;AACpB,gBAAa,OAAO,OAAO,MAAM,4BAA4B,QAAQ;QAErE,cAAa,OAAO,OAAO,MAAM,8BAA8B,QAAQ;AAGzE,SA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AyB,EAAE;IAC3B,UAAU;KACR,OAAO;KACP,QAAQ,iBAAiB;KAC1B;IACF;;;CAIL,MAAc,cAAc,cAA4B,iBAA8C;EAGpG,MAAM,WAAW,MAFS,aAAa,kBAAkB,QAAQ,kBAAkB,CAE1C,YACvC,cACA,OAAO,YAAY,MAAM,QAAQ,SAAS,EAAE,MAAM,iBAAiB,CAAC,CACrE;AAED,MAAI,CAAC,SACH,OAAM,IAAI,WAAW,0BAA0B;EAGjD,MAAM,aAAa,IAAI,WAAW,SAAS,IAAI,YAAY;AAE3D,WAAS,IAAI,OAAO,MAAM;AAE1B,SAAO;;CAGT,MAAc,oBAAoB,cAA4B,KAAa;EAGzE,MAAM,YAAY,MAFI,aAAa,kBAAkB,QAAQ,cAAc,CAErC,eAAe,cAAc,IAAI;AACvE,MAAI,CAAC,UACH,OAAM,IAAI,WAAW,sBAAsB;AAG7C,MAAI,CAAC,UAAU,aAAa,mBAC1B,OAAM,IAAI,WAAW,qDAAqD;AAK5E,SAFwB,UAAU,YAAY,mBAAmB,GAAG;;CAKtE,AAAQ,aAAa,cAAsC;AACzD,MAAI,CAAC,KAAK,UAAU;GAClB,MAAM,iBAAiB,aAAa,kBAAkB,QAAQ,oBAAoB;AAElF,QAAK,WAAW,IAAI,SAAS,YAAY,eAAe,QAAQ,eAAe,mBAAmB,CAAC;;AAGrG,SAAO,KAAK"}
@@ -1,13 +1,12 @@
1
1
  import { AgentContext, DidResolutionResult, DidResolver } from "@credo-ts/core";
2
- import { Resolver } from "did-resolver";
3
2
 
4
3
  //#region src/dids/PolygonDidResolver.d.ts
5
4
  declare class PolygonDidResolver implements DidResolver {
6
5
  readonly allowsCaching = true;
6
+ private resolver?;
7
7
  readonly supportedMethods: string[];
8
- resolver: Resolver;
9
- constructor();
10
8
  resolve(agentContext: AgentContext, did: string): Promise<DidResolutionResult>;
9
+ private _getResolver;
11
10
  }
12
11
  //#endregion
13
12
  export { PolygonDidResolver };
@@ -1 +1 @@
1
- {"version":3,"file":"PolygonDidResolver.d.mts","names":[],"sources":["../../src/dids/PolygonDidResolver.ts"],"mappings":";;;;cAaa,kBAAA,YAA8B,WAAA;EAAA,SACzB,aAAA;EAAA,SAEA,gBAAA;EAET,QAAA,EAAU,QAAA;;EAMJ,OAAA,CAAQ,YAAA,EAAc,YAAA,EAAc,GAAA,WAAc,OAAA,CAAQ,mBAAA;AAAA"}
1
+ {"version":3,"file":"PolygonDidResolver.d.mts","names":[],"sources":["../../src/dids/PolygonDidResolver.ts"],"mappings":";;;cAYa,kBAAA,YAA8B,WAAA;EAAA,SACzB,aAAA;EAAA,QAER,QAAA;EAAA,SAEQ,gBAAA;EAEH,OAAA,CAAQ,YAAA,EAAc,YAAA,EAAc,GAAA,WAAc,OAAA,CAAQ,mBAAA;EAAA,QA2B/D,YAAA;AAAA"}
@@ -1,4 +1,5 @@
1
1
  import { isValidPolygonDid } from "./didPolygonUtil.mjs";
2
+ import { PolygonModuleConfig } from "../PolygonModuleConfig.mjs";
2
3
  import { DidDocument, JsonTransformer } from "@credo-ts/core";
3
4
  import { getResolver } from "@ayanworks/polygon-did-resolver";
4
5
  import { Resolver } from "did-resolver";
@@ -8,13 +9,12 @@ var PolygonDidResolver = class {
8
9
  constructor() {
9
10
  this.allowsCaching = true;
10
11
  this.supportedMethods = ["polygon"];
11
- this.resolver = new Resolver(getResolver());
12
12
  }
13
13
  async resolve(agentContext, did) {
14
14
  const didDocumentMetadata = {};
15
15
  if (!isValidPolygonDid(did)) throw new Error("Invalid DID");
16
16
  try {
17
- const { didDocument, didDocumentMetadata, didResolutionMetadata } = await this.resolver.resolve(did);
17
+ const { didDocument, didDocumentMetadata, didResolutionMetadata } = await this._getResolver(agentContext).resolve(did);
18
18
  return {
19
19
  didDocument: JsonTransformer.fromJSON(didDocument, DidDocument),
20
20
  didDocumentMetadata,
@@ -31,6 +31,13 @@ var PolygonDidResolver = class {
31
31
  };
32
32
  }
33
33
  }
34
+ _getResolver(agentContext) {
35
+ if (!this.resolver) {
36
+ const polygonOptions = agentContext.dependencyManager.resolve(PolygonModuleConfig);
37
+ this.resolver = new Resolver(getResolver(polygonOptions.rpcUrl, polygonOptions.didContractAddress));
38
+ }
39
+ return this.resolver;
40
+ }
34
41
  };
35
42
 
36
43
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"PolygonDidResolver.mjs","names":[],"sources":["../../src/dids/PolygonDidResolver.ts"],"sourcesContent":["import { getResolver } from '@ayanworks/polygon-did-resolver'\nimport {\n type AgentContext,\n DidDocument,\n type DidResolutionResult,\n type DidResolver,\n JsonTransformer,\n} from '@credo-ts/core'\nimport type { ResolverRegistry } from 'did-resolver'\nimport { Resolver } from 'did-resolver'\n\nimport { isValidPolygonDid } from './didPolygonUtil'\n\nexport class PolygonDidResolver implements DidResolver {\n public readonly allowsCaching = true\n\n public readonly supportedMethods = ['polygon']\n\n public resolver: Resolver\n\n public constructor() {\n this.resolver = new Resolver(getResolver() as ResolverRegistry)\n }\n\n public async resolve(agentContext: AgentContext, did: string): Promise<DidResolutionResult> {\n const didDocumentMetadata = {}\n\n if (!isValidPolygonDid(did)) {\n throw new Error('Invalid DID')\n }\n try {\n const { didDocument, didDocumentMetadata, didResolutionMetadata } = await this.resolver.resolve(did)\n\n return {\n didDocument: JsonTransformer.fromJSON(didDocument, DidDocument),\n didDocumentMetadata,\n didResolutionMetadata,\n }\n } catch (error) {\n return {\n didDocument: null,\n didDocumentMetadata,\n didResolutionMetadata: {\n error: 'notFound',\n message: `resolver_error: Unable to resolve did '${did}': ${error}`,\n },\n }\n }\n }\n}\n"],"mappings":";;;;;;AAaA,IAAa,qBAAb,MAAuD;CAOrD,AAAO,cAAc;OANL,gBAAgB;OAEhB,mBAAmB,CAAC,UAAU;AAK5C,OAAK,WAAW,IAAI,SAAS,aAAa,CAAqB;;CAGjE,MAAa,QAAQ,cAA4B,KAA2C;EAC1F,MAAM,sBAAsB,EAAE;AAE9B,MAAI,CAAC,kBAAkB,IAAI,CACzB,OAAM,IAAI,MAAM,cAAc;AAEhC,MAAI;GACF,MAAM,EAAE,aAAa,qBAAqB,0BAA0B,MAAM,KAAK,SAAS,QAAQ,IAAI;AAEpG,UAAO;IACL,aAAa,gBAAgB,SAAS,aAAa,YAAY;IAC/D;IACA;IACD;WACM,OAAO;AACd,UAAO;IACL,aAAa;IACb;IACA,uBAAuB;KACrB,OAAO;KACP,SAAS,0CAA0C,IAAI,KAAK;KAC7D;IACF"}
1
+ {"version":3,"file":"PolygonDidResolver.mjs","names":[],"sources":["../../src/dids/PolygonDidResolver.ts"],"sourcesContent":["import { getResolver } from '@ayanworks/polygon-did-resolver'\nimport {\n type AgentContext,\n DidDocument,\n type DidResolutionResult,\n type DidResolver,\n JsonTransformer,\n} from '@credo-ts/core'\nimport { Resolver } from 'did-resolver'\nimport { PolygonModuleConfig } from '../PolygonModuleConfig'\nimport { isValidPolygonDid } from './didPolygonUtil'\n\nexport class PolygonDidResolver implements DidResolver {\n public readonly allowsCaching = true\n\n private resolver?: Resolver\n\n public readonly supportedMethods = ['polygon']\n\n public async resolve(agentContext: AgentContext, did: string): Promise<DidResolutionResult> {\n const didDocumentMetadata = {}\n\n if (!isValidPolygonDid(did)) {\n throw new Error('Invalid DID')\n }\n try {\n const resolver = this._getResolver(agentContext)\n const { didDocument, didDocumentMetadata, didResolutionMetadata } = await resolver.resolve(did)\n\n return {\n didDocument: JsonTransformer.fromJSON(didDocument, DidDocument),\n didDocumentMetadata,\n didResolutionMetadata,\n }\n } catch (error) {\n return {\n didDocument: null,\n didDocumentMetadata,\n didResolutionMetadata: {\n error: 'notFound',\n message: `resolver_error: Unable to resolve did '${did}': ${error}`,\n },\n }\n }\n }\n\n private _getResolver(agentContext: AgentContext) {\n if (!this.resolver) {\n const polygonOptions = agentContext.dependencyManager.resolve(PolygonModuleConfig)\n\n this.resolver = new Resolver(getResolver(polygonOptions.rpcUrl, polygonOptions.didContractAddress))\n }\n\n return this.resolver\n }\n}\n"],"mappings":";;;;;;;AAYA,IAAa,qBAAb,MAAuD;;OACrC,gBAAgB;OAIhB,mBAAmB,CAAC,UAAU;;CAE9C,MAAa,QAAQ,cAA4B,KAA2C;EAC1F,MAAM,sBAAsB,EAAE;AAE9B,MAAI,CAAC,kBAAkB,IAAI,CACzB,OAAM,IAAI,MAAM,cAAc;AAEhC,MAAI;GAEF,MAAM,EAAE,aAAa,qBAAqB,0BAA0B,MADnD,KAAK,aAAa,aAAa,CACmC,QAAQ,IAAI;AAE/F,UAAO;IACL,aAAa,gBAAgB,SAAS,aAAa,YAAY;IAC/D;IACA;IACD;WACM,OAAO;AACd,UAAO;IACL,aAAa;IACb;IACA,uBAAuB;KACrB,OAAO;KACP,SAAS,0CAA0C,IAAI,KAAK;KAC7D;IACF;;;CAIL,AAAQ,aAAa,cAA4B;AAC/C,MAAI,CAAC,KAAK,UAAU;GAClB,MAAM,iBAAiB,aAAa,kBAAkB,QAAQ,oBAAoB;AAElF,QAAK,WAAW,IAAI,SAAS,YAAY,eAAe,QAAQ,eAAe,mBAAmB,CAAC;;AAGrG,SAAO,KAAK"}
@@ -1,5 +1,7 @@
1
1
  import { SECURITY_CONTEXT_SECP256k1_URL } from "../signature-suites/EcdsaSecp256k1Signature2019.mjs";
2
- import { DidDocumentBuilder, DidDocumentService, VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019, getEcdsaSecp256k1VerificationKey2019 } from "@credo-ts/core";
2
+ import { getCompressedEcdsaSecp256k1VerificationKey2019 } from "../utils/utils.mjs";
3
+ import "../utils/index.mjs";
4
+ import { DidDocumentBuilder, DidDocumentService, VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019 } from "@credo-ts/core";
3
5
  import { Secp256k1PublicJwk } from "@credo-ts/core/kms";
4
6
  import { computeAddress } from "ethers";
5
7
 
@@ -32,7 +34,7 @@ function failedResult(reason) {
32
34
  };
33
35
  }
34
36
  function getSecp256k1DidDoc(did, publicJwk, serviceEndpoint) {
35
- const verificationMethod = getEcdsaSecp256k1VerificationKey2019({
37
+ const verificationMethod = getCompressedEcdsaSecp256k1VerificationKey2019({
36
38
  id: `${did}#key-1`,
37
39
  publicJwk,
38
40
  controller: did
@@ -1 +1 @@
1
- {"version":3,"file":"didPolygonUtil.mjs","names":["Secp256k1PublicJwkClass"],"sources":["../../src/dids/didPolygonUtil.ts"],"sourcesContent":["import type { DidCreateResult, DidDocument } from '@credo-ts/core'\n\nimport {\n DidDocumentBuilder,\n DidDocumentService,\n getEcdsaSecp256k1VerificationKey2019,\n VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019,\n} from '@credo-ts/core'\nimport type { PublicJwk, Secp256k1PublicJwk } from '@credo-ts/core/kms'\nimport { Secp256k1PublicJwk as Secp256k1PublicJwkClass } from '@credo-ts/core/kms'\nimport { computeAddress } from 'ethers'\nimport { SECURITY_CONTEXT_SECP256k1_URL } from '../signature-suites/EcdsaSecp256k1Signature2019'\n\n/**\n * Helper to create Secp256k1PublicJwk from base64url-encoded x and y coordinates.\n * Uses compressed SEC1 format (33 bytes: prefix 02/03 + X coordinate).\n */\nexport function createSecp256k1PublicJwk(publicJwk: { x: string; y: string }): Secp256k1PublicJwk {\n const xBytes = Buffer.from(publicJwk.x, 'base64url')\n const yBytes = Buffer.from(publicJwk.y, 'base64url')\n const prefix = yBytes[yBytes.length - 1] % 2 === 0 ? '02' : '03'\n const compressedKeyHex = prefix + xBytes.toString('hex')\n\n return Secp256k1PublicJwkClass.fromPublicKey(Buffer.from(compressedKeyHex, 'hex'))\n}\n\nexport const polygonDidRegex = new RegExp(/^did:polygon(:testnet)?:0x[0-9a-fA-F]{40}$/)\n\nexport const isValidPolygonDid = (did: string) => polygonDidRegex.test(did)\n\nexport function buildDid(method: string, network: string, publicKey: string): string {\n const address = computeAddress(`0x${publicKey}`)\n\n if (network === 'mainnet') {\n return `did:${method}:${address}`\n }\n\n return `did:${method}:${network}:${address}`\n}\n\nexport function failedResult(reason: string): DidCreateResult {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: reason,\n },\n }\n}\n\nexport function getSecp256k1DidDoc(\n did: string,\n publicJwk: PublicJwk<Secp256k1PublicJwk>,\n serviceEndpoint?: string\n): DidDocument {\n const verificationMethod = getEcdsaSecp256k1VerificationKey2019({\n id: `${did}#key-1`,\n publicJwk,\n controller: did,\n })\n\n const didDocumentBuilder = new DidDocumentBuilder(did)\n didDocumentBuilder.addContext(SECURITY_CONTEXT_SECP256k1_URL).addVerificationMethod(verificationMethod)\n\n if (serviceEndpoint) {\n const service = new DidDocumentService({\n id: `${did}#linked-domain`,\n serviceEndpoint,\n type: 'LinkedDomains',\n })\n didDocumentBuilder.addService(service)\n }\n\n didDocumentBuilder\n .addAuthentication(verificationMethod.id)\n .addAssertionMethod(verificationMethod.id)\n .addCapabilityDelegation(verificationMethod.id)\n .addCapabilityInvocation(verificationMethod.id)\n .addKeyAgreement(verificationMethod.id)\n\n return didDocumentBuilder.build()\n}\n\nexport function validateSpecCompliantPayload(didDocument: DidDocument): string | null {\n // id is required, validated on both compile and runtime\n if (!didDocument.id && !didDocument.id.startsWith('did:polygon:')) return 'id is required'\n\n // verificationMethod is required\n if (!didDocument.verificationMethod) return 'verificationMethod is required'\n\n // verificationMethod must be an array\n if (!Array.isArray(didDocument.verificationMethod)) return 'verificationMethod must be an array'\n\n // verificationMethod must be not be empty\n if (!didDocument.verificationMethod.length) return 'verificationMethod must be not be empty'\n\n // verificationMethod types must be supported\n const isValidVerificationMethod = didDocument.verificationMethod.every((vm) => {\n switch (vm.type) {\n case VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019:\n return vm?.publicKeyBase58 && vm?.controller && vm?.id\n default:\n return false\n }\n })\n\n if (!isValidVerificationMethod) return 'verificationMethod is Invalid'\n\n if (didDocument.service) {\n const isValidService = didDocument.service\n ? didDocument?.service?.every((s) => {\n return s?.serviceEndpoint && s?.id && s?.type\n })\n : true\n\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B,OAAO;;AAGnC,SAAgB,6BAA6B,aAAyC;AAEpF,KAAI,CAAC,YAAY,MAAM,CAAC,YAAY,GAAG,WAAW,eAAe,CAAE,QAAO;AAG1E,KAAI,CAAC,YAAY,mBAAoB,QAAO;AAG5C,KAAI,CAAC,MAAM,QAAQ,YAAY,mBAAmB,CAAE,QAAO;AAG3D,KAAI,CAAC,YAAY,mBAAmB,OAAQ,QAAO;AAYnD,KAAI,CAT8B,YAAY,mBAAmB,OAAO,OAAO;AAC7E,UAAQ,GAAG,MAAX;GACE,KAAK,+DACH,QAAO,IAAI,mBAAmB,IAAI,cAAc,IAAI;GACtD,QACE,QAAO;;GAEX,CAE8B,QAAO;AAEvC,KAAI,YAAY,SAOd;MAAI,EANmB,YAAY,UAC/B,aAAa,SAAS,OAAO,MAAM;AACjC,UAAO,GAAG,mBAAmB,GAAG,MAAM,GAAG;IACzC,GACF,MAEiB,QAAO;;AAG9B,QAAO"}
1
+ {"version":3,"file":"didPolygonUtil.mjs","names":["Secp256k1PublicJwkClass"],"sources":["../../src/dids/didPolygonUtil.ts"],"sourcesContent":["import type { DidCreateResult, DidDocument } from '@credo-ts/core'\n\nimport {\n DidDocumentBuilder,\n DidDocumentService,\n VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019,\n} from '@credo-ts/core'\nimport type { PublicJwk, Secp256k1PublicJwk } from '@credo-ts/core/kms'\nimport { Secp256k1PublicJwk as Secp256k1PublicJwkClass } from '@credo-ts/core/kms'\nimport { computeAddress } from 'ethers'\nimport { SECURITY_CONTEXT_SECP256k1_URL } from '../signature-suites/EcdsaSecp256k1Signature2019'\nimport { getCompressedEcdsaSecp256k1VerificationKey2019 } from '../utils'\n\n/**\n * Helper to create Secp256k1PublicJwk from base64url-encoded x and y coordinates.\n * Uses compressed SEC1 format (33 bytes: prefix 02/03 + X coordinate).\n */\nexport function createSecp256k1PublicJwk(publicJwk: { x: string; y: string }): Secp256k1PublicJwk {\n const xBytes = Buffer.from(publicJwk.x, 'base64url')\n const yBytes = Buffer.from(publicJwk.y, 'base64url')\n const prefix = yBytes[yBytes.length - 1] % 2 === 0 ? '02' : '03'\n const compressedKeyHex = prefix + xBytes.toString('hex')\n\n return Secp256k1PublicJwkClass.fromPublicKey(Buffer.from(compressedKeyHex, 'hex'))\n}\n\nexport const polygonDidRegex = new RegExp(/^did:polygon(:testnet)?:0x[0-9a-fA-F]{40}$/)\n\nexport const isValidPolygonDid = (did: string) => polygonDidRegex.test(did)\n\nexport function buildDid(method: string, network: string, publicKey: string): string {\n const address = computeAddress(`0x${publicKey}`)\n\n if (network === 'mainnet') {\n return `did:${method}:${address}`\n }\n\n return `did:${method}:${network}:${address}`\n}\n\nexport function failedResult(reason: string): DidCreateResult {\n return {\n didDocumentMetadata: {},\n didRegistrationMetadata: {},\n didState: {\n state: 'failed',\n reason: reason,\n },\n }\n}\n\nexport function getSecp256k1DidDoc(\n did: string,\n publicJwk: PublicJwk<Secp256k1PublicJwk>,\n serviceEndpoint?: string\n): DidDocument {\n const verificationMethod = getCompressedEcdsaSecp256k1VerificationKey2019({\n id: `${did}#key-1`,\n publicJwk,\n controller: did,\n })\n\n const didDocumentBuilder = new DidDocumentBuilder(did)\n didDocumentBuilder.addContext(SECURITY_CONTEXT_SECP256k1_URL).addVerificationMethod(verificationMethod)\n\n if (serviceEndpoint) {\n const service = new DidDocumentService({\n id: `${did}#linked-domain`,\n serviceEndpoint,\n type: 'LinkedDomains',\n })\n didDocumentBuilder.addService(service)\n }\n\n didDocumentBuilder\n .addAuthentication(verificationMethod.id)\n .addAssertionMethod(verificationMethod.id)\n .addCapabilityDelegation(verificationMethod.id)\n .addCapabilityInvocation(verificationMethod.id)\n .addKeyAgreement(verificationMethod.id)\n\n return didDocumentBuilder.build()\n}\n\nexport function validateSpecCompliantPayload(didDocument: DidDocument): string | null {\n // id is required, validated on both compile and runtime\n if (!didDocument.id && !didDocument.id.startsWith('did:polygon:')) return 'id is required'\n\n // verificationMethod is required\n if (!didDocument.verificationMethod) return 'verificationMethod is required'\n\n // verificationMethod must be an array\n if (!Array.isArray(didDocument.verificationMethod)) return 'verificationMethod must be an array'\n\n // verificationMethod must be not be empty\n if (!didDocument.verificationMethod.length) return 'verificationMethod must be not be empty'\n\n // verificationMethod types must be supported\n const isValidVerificationMethod = didDocument.verificationMethod.every((vm) => {\n switch (vm.type) {\n case VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019:\n return vm?.publicKeyBase58 && vm?.controller && vm?.id\n default:\n return false\n }\n })\n\n if (!isValidVerificationMethod) return 'verificationMethod is Invalid'\n\n if (didDocument.service) {\n const isValidService = didDocument.service\n ? didDocument?.service?.every((s) => {\n return s?.serviceEndpoint && s?.id && s?.type\n })\n : true\n\n if (!isValidService) return 'Service is Invalid'\n }\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,SAAgB,yBAAyB,WAAyD;CAChG,MAAM,SAAS,OAAO,KAAK,UAAU,GAAG,YAAY;CACpD,MAAM,SAAS,OAAO,KAAK,UAAU,GAAG,YAAY;CAEpD,MAAM,oBADS,OAAO,OAAO,SAAS,KAAK,MAAM,IAAI,OAAO,QAC1B,OAAO,SAAS,MAAM;AAExD,QAAOA,mBAAwB,cAAc,OAAO,KAAK,kBAAkB,MAAM,CAAC;;AAGpF,MAAa,kCAAkB,IAAI,OAAO,6CAA6C;AAEvF,MAAa,qBAAqB,QAAgB,gBAAgB,KAAK,IAAI;AAE3E,SAAgB,SAAS,QAAgB,SAAiB,WAA2B;CACnF,MAAM,UAAU,eAAe,KAAK,YAAY;AAEhD,KAAI,YAAY,UACd,QAAO,OAAO,OAAO,GAAG;AAG1B,QAAO,OAAO,OAAO,GAAG,QAAQ,GAAG;;AAGrC,SAAgB,aAAa,QAAiC;AAC5D,QAAO;EACL,qBAAqB,EAAE;EACvB,yBAAyB,EAAE;EAC3B,UAAU;GACR,OAAO;GACC;GACT;EACF;;AAGH,SAAgB,mBACd,KACA,WACA,iBACa;CACb,MAAM,qBAAqB,+CAA+C;EACxE,IAAI,GAAG,IAAI;EACX;EACA,YAAY;EACb,CAAC;CAEF,MAAM,qBAAqB,IAAI,mBAAmB,IAAI;AACtD,oBAAmB,WAAW,+BAA+B,CAAC,sBAAsB,mBAAmB;AAEvG,KAAI,iBAAiB;EACnB,MAAM,UAAU,IAAI,mBAAmB;GACrC,IAAI,GAAG,IAAI;GACX;GACA,MAAM;GACP,CAAC;AACF,qBAAmB,WAAW,QAAQ;;AAGxC,oBACG,kBAAkB,mBAAmB,GAAG,CACxC,mBAAmB,mBAAmB,GAAG,CACzC,wBAAwB,mBAAmB,GAAG,CAC9C,wBAAwB,mBAAmB,GAAG,CAC9C,gBAAgB,mBAAmB,GAAG;AAEzC,QAAO,mBAAmB,OAAO;;AAGnC,SAAgB,6BAA6B,aAAyC;AAEpF,KAAI,CAAC,YAAY,MAAM,CAAC,YAAY,GAAG,WAAW,eAAe,CAAE,QAAO;AAG1E,KAAI,CAAC,YAAY,mBAAoB,QAAO;AAG5C,KAAI,CAAC,MAAM,QAAQ,YAAY,mBAAmB,CAAE,QAAO;AAG3D,KAAI,CAAC,YAAY,mBAAmB,OAAQ,QAAO;AAYnD,KAAI,CAT8B,YAAY,mBAAmB,OAAO,OAAO;AAC7E,UAAQ,GAAG,MAAX;GACE,KAAK,+DACH,QAAO,IAAI,mBAAmB,IAAI,cAAc,IAAI;GACtD,QACE,QAAO;;GAEX,CAE8B,QAAO;AAEvC,KAAI,YAAY,SAOd;MAAI,EANmB,YAAY,UAC/B,aAAa,SAAS,OAAO,MAAM;AACjC,UAAO,GAAG,mBAAmB,GAAG,MAAM,GAAG;IACzC,GACF,MAEiB,QAAO;;AAG9B,QAAO"}
package/build/index.d.mts CHANGED
@@ -6,6 +6,6 @@ import { PolygonModuleConfig, PolygonModuleConfigOptions } from "./PolygonModule
6
6
  import { AddResourceDidOperationOptions, CreateDidOperationOptions, CreateSchemaOperationOptions, DeactivateDidOperationOptions, DidOperation, DidOperationOptions, PolygonLedgerService, SchemaOperation, SchemaOperationOptions, UpdateDidOperationOptions } from "./ledger/PolygonLedgerService.mjs";
7
7
  import "./ledger/index.mjs";
8
8
  import { PolygonModule } from "./PolygonModule.mjs";
9
- import { generateSecp256k1KeyPair, getSecp256k1DidDocWithPublicKey } from "./utils/utils.mjs";
9
+ import { generateSecp256k1KeyPair, getCompressedEcdsaSecp256k1VerificationKey2019, getSecp256k1DidDocWithPublicKey } from "./utils/utils.mjs";
10
10
  import "./utils/index.mjs";
11
- export { AddResourceDidOperationOptions, CreateDidOperationOptions, CreateSchemaOperationOptions, DeactivateDidOperationOptions, DidOperation, DidOperationOptions, PolygonDidCreateOptions, PolygonDidRegistrar, PolygonDidResolver, PolygonDidUpdateOptions, PolygonLedgerService, PolygonModule, PolygonModuleConfig, PolygonModuleConfigOptions, SchemaOperation, SchemaOperationOptions, UpdateDidOperationOptions, buildDid, createSecp256k1PublicJwk, failedResult, generateSecp256k1KeyPair, getSecp256k1DidDoc, getSecp256k1DidDocWithPublicKey, isValidPolygonDid, polygonDidRegex, validateSpecCompliantPayload };
11
+ export { AddResourceDidOperationOptions, CreateDidOperationOptions, CreateSchemaOperationOptions, DeactivateDidOperationOptions, DidOperation, DidOperationOptions, PolygonDidCreateOptions, PolygonDidRegistrar, PolygonDidResolver, PolygonDidUpdateOptions, PolygonLedgerService, PolygonModule, PolygonModuleConfig, PolygonModuleConfigOptions, SchemaOperation, SchemaOperationOptions, UpdateDidOperationOptions, buildDid, createSecp256k1PublicJwk, failedResult, generateSecp256k1KeyPair, getCompressedEcdsaSecp256k1VerificationKey2019, getSecp256k1DidDoc, getSecp256k1DidDocWithPublicKey, isValidPolygonDid, polygonDidRegex, validateSpecCompliantPayload };
package/build/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
+ import { generateSecp256k1KeyPair, getCompressedEcdsaSecp256k1VerificationKey2019, getSecp256k1DidDocWithPublicKey } from "./utils/utils.mjs";
2
+ import "./utils/index.mjs";
1
3
  import { buildDid, createSecp256k1PublicJwk, failedResult, getSecp256k1DidDoc, isValidPolygonDid, polygonDidRegex, validateSpecCompliantPayload } from "./dids/didPolygonUtil.mjs";
2
4
  import { PolygonModuleConfig } from "./PolygonModuleConfig.mjs";
3
- import { generateSecp256k1KeyPair, getSecp256k1DidDocWithPublicKey } from "./utils/utils.mjs";
4
- import "./utils/index.mjs";
5
5
  import { DidOperation, PolygonLedgerService, SchemaOperation } from "./ledger/PolygonLedgerService.mjs";
6
6
  import "./ledger/index.mjs";
7
7
  import { PolygonDidRegistrar } from "./dids/PolygonDidRegistrar.mjs";
@@ -9,4 +9,4 @@ import { PolygonDidResolver } from "./dids/PolygonDidResolver.mjs";
9
9
  import "./dids/index.mjs";
10
10
  import { PolygonModule } from "./PolygonModule.mjs";
11
11
 
12
- export { DidOperation, PolygonDidRegistrar, PolygonDidResolver, PolygonLedgerService, PolygonModule, PolygonModuleConfig, SchemaOperation, buildDid, createSecp256k1PublicJwk, failedResult, generateSecp256k1KeyPair, getSecp256k1DidDoc, getSecp256k1DidDocWithPublicKey, isValidPolygonDid, polygonDidRegex, validateSpecCompliantPayload };
12
+ export { DidOperation, PolygonDidRegistrar, PolygonDidResolver, PolygonLedgerService, PolygonModule, PolygonModuleConfig, SchemaOperation, buildDid, createSecp256k1PublicJwk, failedResult, generateSecp256k1KeyPair, getCompressedEcdsaSecp256k1VerificationKey2019, getSecp256k1DidDoc, getSecp256k1DidDocWithPublicKey, isValidPolygonDid, polygonDidRegex, validateSpecCompliantPayload };
@@ -2,6 +2,7 @@ import { PolygonModuleConfig } from "../PolygonModuleConfig.mjs";
2
2
  import { AgentContext, DidDocument } from "@credo-ts/core";
3
3
  import { SigningKey } from "ethers";
4
4
  import { PolygonDID } from "@ayanworks/polygon-did-registrar";
5
+ import { EstimatedTxDetails } from "@ayanworks/polygon-schema-manager";
5
6
 
6
7
  //#region src/ledger/PolygonLedgerService.d.ts
7
8
  interface SchemaRegistryConfig {
@@ -88,16 +89,7 @@ declare class PolygonLedgerService {
88
89
  resourceTxnHash?: undefined;
89
90
  }>;
90
91
  getSchemaByDidAndSchemaId(agentContext: AgentContext, did: string, schemaId: string): Promise<any>;
91
- estimateFeeForDidOperation(agentContext: AgentContext, options: DidOperationOptions): Promise<{
92
- transactionFee: string;
93
- gasLimit: string;
94
- gasPrice: string;
95
- maxFeePerGas: number;
96
- maxPriorityFeePerGas: number;
97
- network: string;
98
- chainId: string;
99
- method: string;
100
- } | null | undefined>;
92
+ estimateFeeForDidOperation(agentContext: AgentContext, options: DidOperationOptions): Promise<EstimatedTxDetails | null>;
101
93
  estimateFeeForSchemaOperation(agentContext: AgentContext, options: SchemaOperationOptions): Promise<{} | undefined>;
102
94
  createDidRegistryInstance(signingKey: SigningKey): PolygonDID;
103
95
  private createSchemaRegistryInstance;
@@ -1 +1 @@
1
- {"version":3,"file":"PolygonLedgerService.d.mts","names":[],"sources":["../../src/ledger/PolygonLedgerService.ts"],"mappings":";;;;;;UASU,oBAAA;EACR,2BAAA;EACA,MAAA;EACA,eAAA;EACA,UAAA;EACA,4BAAA;EACA,SAAA;AAAA;AAAA,KAGU,yBAAA;EACV,SAAA,EAAW,YAAA,CAAa,MAAA;EACxB,eAAA;AAAA;AAAA,KAGU,yBAAA;EACV,SAAA,EAAW,YAAA,CAAa,MAAA;EACxB,WAAA,EAAa,WAAA;EACb,GAAA;AAAA;AAAA,KAGU,6BAAA;EACV,SAAA,EAAW,YAAA,CAAa,UAAA;EACxB,GAAA;AAAA;AAAA,KAGU,8BAAA;EACV,SAAA,EAAW,YAAA,CAAa,WAAA;EACxB,UAAA;EACA,QAAA;EACA,GAAA;AAAA;AAAA,aAGU,YAAA;EACV,MAAA;EACA,MAAA;EACA,UAAA;EACA,WAAA;AAAA;AAAA,KAGU,mBAAA,GACR,yBAAA,GACA,yBAAA,GACA,6BAAA,GACA,8BAAA;AAAA,KAEQ,sBAAA,GAAyB,4BAAA;AAAA,KAEzB,4BAAA;EACV,SAAA,EAAW,eAAA,CA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mjs";
2
1
  import { generateSecp256k1KeyPair, getSecp256k1DidDocWithPublicKey } from "../utils/utils.mjs";
3
2
  import "../utils/index.mjs";
3
+ import { PolygonModuleConfig } from "../PolygonModuleConfig.mjs";
4
4
  import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.110.0/helpers/decorateMetadata.mjs";
5
5
  import { __decorate } from "../_virtual/_@oxc-project_runtime@0.110.0/helpers/decorate.mjs";
6
6
  import { CredoError, DidDocumentBuilder, DidRepository, injectable, utils } from "@credo-ts/core";
7
7
  import { SigningKey } from "ethers";
8
- import { AskarStoreManager } from "@credo-ts/askar";
9
8
  import { PolygonDID } from "@ayanworks/polygon-did-registrar";
9
+ import { AskarStoreManager } from "@credo-ts/askar";
10
10
  import { PolygonSchema } from "@ayanworks/polygon-schema-manager";
11
11
 
12
12
  //#region src/ledger/PolygonLedgerService.ts
@@ -86,6 +86,7 @@ let PolygonLedgerService = class PolygonLedgerService {
86
86
  JSON.stringify(options.resource)
87
87
  ], address);
88
88
  }
89
+ return null;
89
90
  }
90
91
  async estimateFeeForSchemaOperation(agentContext, options) {
91
92
  const keyPair = await generateSecp256k1KeyPair();
@@ -1 +1 @@
1
- {"version":3,"file":"PolygonLedgerService.mjs","names":[],"sources":["../../src/ledger/PolygonLedgerService.ts"],"sourcesContent":["import { PolygonDID } from '@ayanworks/polygon-did-registrar'\nimport { PolygonSchema } from '@ayanworks/polygon-schema-manager'\nimport { AskarStoreManager } from '@credo-ts/askar'\nimport type { AgentContext, DidDocument } from '@credo-ts/core'\nimport { CredoError, DidDocumentBuilder, DidRepository, injectable, utils } from '@credo-ts/core'\nimport { SigningKey } from 'ethers'\nimport { PolygonModuleConfig } from '../PolygonModuleConfig'\nimport { generateSecp256k1KeyPair, getSecp256k1DidDocWithPublicKey } from '../utils'\n\ninterface SchemaRegistryConfig {\n didRegistrarContractAddress: string\n rpcUrl: string\n fileServerToken: string\n privateKey: string\n schemaManagerContractAddress: string\n serverUrl: string\n}\n\nexport type CreateDidOperationOptions = {\n operation: DidOperation.Create\n serviceEndpoint?: string\n}\n\nexport type UpdateDidOperationOptions = {\n operation: DidOperation.Update\n didDocument: DidDocument\n did: string\n}\n\nexport type DeactivateDidOperationOptions = {\n operation: DidOperation.Deactivate\n did: string\n}\n\nexport type AddResourceDidOperationOptions = {\n operation: DidOperation.AddResource\n resourceId: string\n resource: object\n did: string\n}\n\nexport enum DidOperation {\n Create = 'createDID',\n Update = 'updateDIDDoc',\n Deactivate = 'deactivate',\n AddResource = 'addResource',\n}\n\nexport type DidOperationOptions =\n | CreateDidOperationOptions\n | UpdateDidOperationOptions\n | DeactivateDidOperationOptions\n | AddResourceDidOperationOptions\n\nexport type SchemaOperationOptions = CreateSchemaOperationOptions\n\nexport type CreateSchemaOperationOptions = {\n operation: SchemaOperation.CreateSchema\n did: string\n}\n\nexport enum SchemaOperation {\n CreateSchema = 'createSchema',\n}\n\n@injectable()\nexport class PolygonLedgerService {\n public rpcUrl: string | undefined\n private didContractAddress: string | undefined\n private schemaManagerContractAddress: string | undefined\n private fileServerToken: string | undefined\n private fileServerUrl: string | undefined\n\n public constructor({\n didContractAddress,\n rpcUrl,\n fileServerToken,\n schemaManagerContractAddress,\n serverUrl,\n }: PolygonModuleConfig) {\n this.rpcUrl = rpcUrl\n this.didContractAddress = didContractAddress\n this.schemaManagerContractAddress = schemaManagerContractAddress\n this.fileServerToken = fileServerToken\n this.fileServerUrl = serverUrl\n }\n\n public async createSchema(\n agentContext: AgentContext,\n { did, schemaName, schema }: { did: string; schemaName: string; schema: object }\n ) {\n const publicKeyBase58 = await this.getPublicKeyFromDid(agentContext, did)\n\n if (!publicKeyBase58) {\n throw new CredoError('Public Key not found in wallet')\n }\n\n const signingKey = await this.getSigningKey(agentContext, publicKeyBase58)\n\n const schemaRegistry = this.createSchemaRegistryInstance(signingKey)\n\n agentContext.config.logger.info(`Creating schema on ledger: ${did}`)\n\n const response = await schemaRegistry.createSchema(did, schemaName, schema)\n if (!response) {\n agentContext.config.logger.error(`Schema creation failed for did: ${did} and schema: ${schema}`)\n throw new CredoError(`Schema creation failed for did: ${did} and schema: ${schema}`)\n }\n agentContext.config.logger.info(`Published schema on ledger: ${did}`)\n return response\n }\n\n public async getSchemaByDidAndSchemaId(agentContext: AgentContext, did: string, schemaId: string) {\n agentContext.config.logger.info(`Getting schema from ledger: ${did} and schemaId: ${schemaId}`)\n\n const publicKeyBase58 = await this.getPublicKeyFromDid(agentContext, did)\n\n if (!publicKeyBase58) {\n throw new CredoError('Public Key not found in wallet')\n }\n\n const signingKey = await this.getSigningKey(agentContext, publicKeyBase58)\n\n const schemaRegistry = this.createSchemaRegistryInstance(signingKey)\n\n const response = await schemaRegistry.getSchemaById(did, schemaId)\n\n if (!response) {\n agentContext.config.logger.error(`Schema not found for did: ${did} and schemaId: ${schemaId} Error: ${response}`)\n throw new CredoError(`Schema not found for did: ${did} and schemaId: ${schemaId}`)\n }\n agentContext.config.logger.info(`Got schema from ledger: ${did} and schemaId: ${schemaId}`)\n return response\n }\n\n public async estimateFeeForDidOperation(agentContext: AgentContext, options: DidOperationOptions) {\n const keyPair = await generateSecp256k1KeyPair()\n\n const didRegistry = this.createDidRegistryInstance(new SigningKey(keyPair.privateKey))\n\n const { operation } = options\n\n if (operation === DidOperation.Create) {\n agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `)\n const did = `did:polygon:testnet${keyPair.address}`\n const didDoc = getSecp256k1DidDocWithPublicKey(did, keyPair.publicKeyBase58, options?.serviceEndpoint)\n\n const response = await didRegistry.estimateTxFee(DidOperation.Create, [keyPair.address, JSON.stringify(didDoc)])\n return response\n }\n\n if (operation === DidOperation.Update) {\n agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `)\n const address = options.did.split(':').pop() || ''\n\n const response = await didRegistry.estimateTxFee(\n DidOperation.Update,\n [address, JSON.stringify(options.didDocument)],\n address\n )\n return response\n }\n\n if (operation === DidOperation.Deactivate) {\n agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `)\n const address = options.did.split(':').pop() || ''\n const deactivatedDidDocument = new DidDocumentBuilder(options.did)\n .addContext('https://www.w3.org/ns/did/v1')\n .build()\n const response = await didRegistry.estimateTxFee(\n DidOperation.Update,\n [address, JSON.stringify(deactivatedDidDocument)],\n address\n )\n return response\n }\n\n if (operation === DidOperation.AddResource) {\n agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `)\n const address = options.did.split(':').pop() || ''\n const response = await didRegistry.estimateTxFee(\n DidOperation.AddResource,\n [address, options.resourceId, JSON.stringify(options.resource)],\n address\n )\n return response\n }\n }\n\n public async estimateFeeForSchemaOperation(agentContext: AgentContext, options: SchemaOperationOptions) {\n const keyPair = await generateSecp256k1KeyPair()\n\n const schemaRegistry = this.createSchemaRegistryInstance(new SigningKey(keyPair.privateKey))\n\n const { operation } = options\n\n const testResourceBody = {\n resourceURI:\n 'did:polygon:testnet:0x13cd23928Ae515b86592C630f56C138aE4c7B79a/resources/398cee0a-efac-4643-9f4c-74c48c72a14b',\n resourceCollectionId: '55dbc8bf-fba3-4117-855c-1e0dc1d3bb47',\n resourceId: '398cee0a-efac-4643-9f4c-74c48c72a14b',\n resourceName: 'Eventbrite1 Logo',\n resourceType: 'W3C-schema',\n mediaType: 'image/svg+xml',\n created: '2022-11-17T08:10:36Z',\n checksum: 'a95380f460e63ad939541a57aecbfd795fcd37c6d78ee86c885340e33a91b559',\n previousVersionId: null,\n nextVersionId: null,\n }\n\n if (operation === SchemaOperation.CreateSchema) {\n agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `)\n const schemaEstimatedFee = await schemaRegistry.estimateTxFee(SchemaOperation.CreateSchema, [\n keyPair.address,\n utils.uuid(),\n JSON.stringify(testResourceBody),\n ])\n\n const resourceEstimatedFee = await this.estimateFeeForDidOperation(agentContext, {\n operation: DidOperation.AddResource,\n resourceId: utils.uuid(),\n resource: testResourceBody,\n did: options.did,\n })\n\n let feeParameters = {}\n\n if (schemaEstimatedFee && resourceEstimatedFee) {\n feeParameters = {\n estimatedTotalTxFee: Number(schemaEstimatedFee.transactionFee) + Number(resourceEstimatedFee.transactionFee),\n estimatedSchemaTxFee: schemaEstimatedFee,\n estimatedResourceTxFee: resourceEstimatedFee,\n }\n }\n\n return feeParameters\n }\n }\n\n public createDidRegistryInstance(signingKey: SigningKey) {\n if (!this.rpcUrl || !this.didContractAddress) {\n throw new CredoError('Ledger config not found')\n }\n\n return new PolygonDID({\n rpcUrl: this.rpcUrl,\n contractAddress: this.didContractAddress,\n signingKey,\n })\n }\n\n private createSchemaRegistryInstance(signingKey: SigningKey) {\n if (\n !this.rpcUrl ||\n !this.schemaManagerContractAddress ||\n !this.fileServerToken ||\n !this.fileServerUrl ||\n !this.didContractAddress\n ) {\n throw new CredoError('Polygon schema module config not found')\n }\n\n return new PolygonSchema({\n rpcUrl: this.rpcUrl,\n didRegistrarContractAddress: this.didContractAddress,\n schemaManagerContractAddress: this.schemaManagerContractAddress,\n fileServerToken: this.fileServerToken,\n serverUrl: this.fileServerUrl,\n signingKey,\n })\n }\n\n private async getSigningKey(agentContext: AgentContext, publicKeyBase58: string): Promise<SigningKey> {\n const askarStoreManager = agentContext.dependencyManager.resolve(AskarStoreManager)\n\n const keyEntry = await askarStoreManager.withSession(\n agentContext,\n async (session) => await session.fetchKey({ name: publicKeyBase58 })\n )\n\n if (!keyEntry) {\n throw new CredoError('Key not found in wallet')\n }\n\n const signingKey = new SigningKey(keyEntry.key.secretBytes)\n\n keyEntry.key.handle.free()\n\n return signingKey\n }\n\n private async getPublicKeyFromDid(agentContext: AgentContext, did: string) {\n const didRepository = agentContext.dependencyManager.resolve(DidRepository)\n\n const didRecord = await didRepository.findCreatedDid(agentContext, did)\n if (!didRecord) {\n throw new CredoError('DidRecord not found')\n }\n\n if (!didRecord.didDocument?.verificationMethod) {\n throw new CredoError('VerificationMethod not found cannot get public key')\n }\n\n const publicKeyBase58 = didRecord.didDocument.verificationMethod[0].publicKeyBase58\n\n return publicKeyBase58\n }\n\n public updateModuleConfig({\n didRegistrarContractAddress,\n fileServerToken,\n rpcUrl,\n schemaManagerContractAddress,\n serverUrl,\n }: SchemaRegistryConfig) {\n this.rpcUrl = rpcUrl\n this.didContractAddress = didRegistrarContractAddress\n this.schemaManagerContractAddress = schemaManagerContractAddress\n this.fileServerToken = fileServerToken\n this.fileServerUrl = serverUrl\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAyCA,IAAY,sDAAL;AACL;AACA;AACA;AACA;;;AAgBF,IAAY,4DAAL;AACL;;;AAIK,iCAAM,qBAAqB;CAOhC,AAAO,YAAY,EACjB,oBACA,QACA,iBACA,8BACA,aACsB;AACtB,OAAK,SAAS;AACd,OAAK,qBAAqB;AAC1B,OAAK,+BAA+B;AACpC,OAAK,kBAAkB;AACvB,OAAK,gBAAgB;;CAGvB,MAAa,aACX,cACA,EAAE,KAAK,YAAY,UACnB;EACA,MAAM,kBAAkB,MAAM,KAAK,oBAAoB,cAAc,IAAI;AAEzE,MAAI,CAAC,gBACH,OAAM,IAAI,WAAW,iCAAiC;EAGxD,MAAM,aAAa,MAAM,KAAK,cAAc,cAAc,gBAAgB;EAE1E,MAAM,iBAAiB,KAAK,6BAA6B,WAAW;AAEpE,eAAa,OAAO,OAAO,KAAK,8BAA8B,MAAM;EAEpE,MAAM,WAAW,MAAM,eAAe,aAAa,KAAK,YAAY,OAAO;AAC3E,MAAI,CAAC,UAAU;AACb,gBAAa,OAAO,OAAO,MAAM,mCAAmC,IAAI,eAAe,SAAS;AAChG,SAAM,IAAI,WAAW,mCAAmC,IAAI,eAAe,SAAS;;AAEtF,eAAa,OAAO,OAAO,KAAK,+BAA+B,MAAM;AACrE,SAAO;;CAGT,MAAa,0BAA0B,cAA4B,KAAa,UAAkB;AAChG,eAAa,OAAO,OAAO,KAAK,+BAA+B,IAAI,iBAAiB,WAAW;EAE/F,MAAM,kBAAkB,MAAM,KAAK,oBAAoB,cAAc,IAAI;AAEzE,MAAI,CAAC,gBACH,OAAM,IAAI,WAAW,iCAAiC;E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onLedgerService.ts"],"sourcesContent":["import { PolygonDID } from '@ayanworks/polygon-did-registrar'\nimport { type EstimatedTxDetails, PolygonSchema } from '@ayanworks/polygon-schema-manager'\nimport { AskarStoreManager } from '@credo-ts/askar'\nimport type { AgentContext, DidDocument } from '@credo-ts/core'\nimport { CredoError, DidDocumentBuilder, DidRepository, injectable, utils } from '@credo-ts/core'\nimport { SigningKey } from 'ethers'\nimport { PolygonModuleConfig } from '../PolygonModuleConfig'\nimport { generateSecp256k1KeyPair, getSecp256k1DidDocWithPublicKey } from '../utils'\n\ninterface SchemaRegistryConfig {\n didRegistrarContractAddress: string\n rpcUrl: string\n fileServerToken: string\n privateKey: string\n schemaManagerContractAddress: string\n serverUrl: string\n}\n\nexport type CreateDidOperationOptions = {\n operation: DidOperation.Create\n serviceEndpoint?: string\n}\n\nexport type UpdateDidOperationOptions = {\n operation: DidOperation.Update\n didDocument: DidDocument\n did: string\n}\n\nexport type DeactivateDidOperationOptions = {\n operation: DidOperation.Deactivate\n did: string\n}\n\nexport type AddResourceDidOperationOptions = {\n operation: DidOperation.AddResource\n resourceId: string\n resource: object\n did: string\n}\n\nexport enum DidOperation {\n Create = 'createDID',\n Update = 'updateDIDDoc',\n Deactivate = 'deactivate',\n AddResource = 'addResource',\n}\n\nexport type DidOperationOptions =\n | CreateDidOperationOptions\n | UpdateDidOperationOptions\n | DeactivateDidOperationOptions\n | AddResourceDidOperationOptions\n\nexport type SchemaOperationOptions = CreateSchemaOperationOptions\n\nexport type CreateSchemaOperationOptions = {\n operation: SchemaOperation.CreateSchema\n did: string\n}\n\nexport enum SchemaOperation {\n CreateSchema = 'createSchema',\n}\n\n@injectable()\nexport class PolygonLedgerService {\n public rpcUrl: string | undefined\n private didContractAddress: string | undefined\n private schemaManagerContractAddress: string | undefined\n private fileServerToken: string | undefined\n private fileServerUrl: string | undefined\n\n public constructor({\n didContractAddress,\n rpcUrl,\n fileServerToken,\n schemaManagerContractAddress,\n serverUrl,\n }: PolygonModuleConfig) {\n this.rpcUrl = rpcUrl\n this.didContractAddress = didContractAddress\n this.schemaManagerContractAddress = schemaManagerContractAddress\n this.fileServerToken = fileServerToken\n this.fileServerUrl = serverUrl\n }\n\n public async createSchema(\n agentContext: AgentContext,\n { did, schemaName, schema }: { did: string; schemaName: string; schema: object }\n ) {\n const publicKeyBase58 = await this.getPublicKeyFromDid(agentContext, did)\n\n if (!publicKeyBase58) {\n throw new CredoError('Public Key not found in wallet')\n }\n\n const signingKey = await this.getSigningKey(agentContext, publicKeyBase58)\n\n const schemaRegistry = this.createSchemaRegistryInstance(signingKey)\n\n agentContext.config.logger.info(`Creating schema on ledger: ${did}`)\n\n const response = await schemaRegistry.createSchema(did, schemaName, schema)\n if (!response) {\n agentContext.config.logger.error(`Schema creation failed for did: ${did} and schema: ${schema}`)\n throw new CredoError(`Schema creation failed for did: ${did} and schema: ${schema}`)\n }\n agentContext.config.logger.info(`Published schema on ledger: ${did}`)\n return response\n }\n\n public async getSchemaByDidAndSchemaId(agentContext: AgentContext, did: string, schemaId: string) {\n agentContext.config.logger.info(`Getting schema from ledger: ${did} and schemaId: ${schemaId}`)\n\n const publicKeyBase58 = await this.getPublicKeyFromDid(agentContext, did)\n\n if (!publicKeyBase58) {\n throw new CredoError('Public Key not found in wallet')\n }\n\n const signingKey = await this.getSigningKey(agentContext, publicKeyBase58)\n\n const schemaRegistry = this.createSchemaRegistryInstance(signingKey)\n\n const response = await schemaRegistry.getSchemaById(did, schemaId)\n\n if (!response) {\n agentContext.config.logger.error(`Schema not found for did: ${did} and schemaId: ${schemaId} Error: ${response}`)\n throw new CredoError(`Schema not found for did: ${did} and schemaId: ${schemaId}`)\n }\n agentContext.config.logger.info(`Got schema from ledger: ${did} and schemaId: ${schemaId}`)\n return response\n }\n\n public async estimateFeeForDidOperation(\n agentContext: AgentContext,\n options: DidOperationOptions\n ): Promise<EstimatedTxDetails | null> {\n const keyPair = await generateSecp256k1KeyPair()\n\n const didRegistry = this.createDidRegistryInstance(new SigningKey(keyPair.privateKey))\n\n const { operation } = options\n\n if (operation === DidOperation.Create) {\n agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `)\n const did = `did:polygon:testnet${keyPair.address}`\n const didDoc = getSecp256k1DidDocWithPublicKey(did, keyPair.publicKeyBase58, options?.serviceEndpoint)\n\n const response = await didRegistry.estimateTxFee(DidOperation.Create, [keyPair.address, JSON.stringify(didDoc)])\n return response\n }\n\n if (operation === DidOperation.Update) {\n agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `)\n const address = options.did.split(':').pop() || ''\n\n const response = await didRegistry.estimateTxFee(\n DidOperation.Update,\n [address, JSON.stringify(options.didDocument)],\n address\n )\n return response\n }\n\n if (operation === DidOperation.Deactivate) {\n agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `)\n const address = options.did.split(':').pop() || ''\n const deactivatedDidDocument = new DidDocumentBuilder(options.did)\n .addContext('https://www.w3.org/ns/did/v1')\n .build()\n const response = await didRegistry.estimateTxFee(\n DidOperation.Update,\n [address, JSON.stringify(deactivatedDidDocument)],\n address\n )\n return response\n }\n\n if (operation === DidOperation.AddResource) {\n agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `)\n const address = options.did.split(':').pop() || ''\n const response = await didRegistry.estimateTxFee(\n DidOperation.AddResource,\n [address, options.resourceId, JSON.stringify(options.resource)],\n address\n )\n return response\n }\n\n return null\n }\n\n public async estimateFeeForSchemaOperation(agentContext: AgentContext, options: SchemaOperationOptions) {\n const keyPair = await generateSecp256k1KeyPair()\n\n const schemaRegistry = this.createSchemaRegistryInstance(new SigningKey(keyPair.privateKey))\n\n const { operation } = options\n\n const testResourceBody = {\n resourceURI:\n 'did:polygon:testnet:0x13cd23928Ae515b86592C630f56C138aE4c7B79a/resources/398cee0a-efac-4643-9f4c-74c48c72a14b',\n resourceCollectionId: '55dbc8bf-fba3-4117-855c-1e0dc1d3bb47',\n resourceId: '398cee0a-efac-4643-9f4c-74c48c72a14b',\n resourceName: 'Eventbrite1 Logo',\n resourceType: 'W3C-schema',\n mediaType: 'image/svg+xml',\n created: '2022-11-17T08:10:36Z',\n checksum: 'a95380f460e63ad939541a57aecbfd795fcd37c6d78ee86c885340e33a91b559',\n previousVersionId: null,\n nextVersionId: null,\n }\n\n if (operation === SchemaOperation.CreateSchema) {\n agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `)\n const schemaEstimatedFee = await schemaRegistry.estimateTxFee(SchemaOperation.CreateSchema, [\n keyPair.address,\n utils.uuid(),\n JSON.stringify(testResourceBody),\n ])\n\n const resourceEstimatedFee = await this.estimateFeeForDidOperation(agentContext, {\n operation: DidOperation.AddResource,\n resourceId: utils.uuid(),\n resource: testResourceBody,\n did: options.did,\n })\n\n let feeParameters = {}\n\n if (schemaEstimatedFee && resourceEstimatedFee) {\n feeParameters = {\n estimatedTotalTxFee: Number(schemaEstimatedFee.transactionFee) + Number(resourceEstimatedFee.transactionFee),\n estimatedSchemaTxFee: schemaEstimatedFee,\n estimatedResourceTxFee: resourceEstimatedFee,\n }\n }\n\n return feeParameters\n }\n }\n\n public createDidRegistryInstance(signingKey: SigningKey) {\n if (!this.rpcUrl || !this.didContractAddress) {\n throw new CredoError('Ledger config not found')\n }\n\n return new PolygonDID({\n rpcUrl: this.rpcUrl,\n contractAddress: this.didContractAddress,\n signingKey,\n })\n }\n\n private createSchemaRegistryInstance(signingKey: SigningKey) {\n if (\n !this.rpcUrl ||\n !this.schemaManagerContractAddress ||\n !this.fileServerToken ||\n !this.fileServerUrl ||\n !this.didContractAddress\n ) {\n throw new CredoError('Polygon schema module config not found')\n }\n\n return new PolygonSchema({\n rpcUrl: this.rpcUrl,\n didRegistrarContractAddress: this.didContractAddress,\n schemaManagerContractAddress: this.schemaManagerContractAddress,\n fileServerToken: this.fileServerToken,\n serverUrl: this.fileServerUrl,\n signingKey,\n })\n }\n\n private async getSigningKey(agentContext: AgentContext, publicKeyBase58: string): Promise<SigningKey> {\n const askarStoreManager = agentContext.dependencyManager.resolve(AskarStoreManager)\n\n const keyEntry = await askarStoreManager.withSession(\n agentContext,\n async (session) => await session.fetchKey({ name: publicKeyBase58 })\n )\n\n if (!keyEntry) {\n throw new CredoError('Key not found in wallet')\n }\n\n const signingKey = new SigningKey(keyEntry.key.secretBytes)\n\n keyEntry.key.handle.free()\n\n return signingKey\n }\n\n private async getPublicKeyFromDid(agentContext: AgentContext, did: string) {\n const didRepository = agentContext.dependencyManager.resolve(DidRepository)\n\n const didRecord = await didRepository.findCreatedDid(agentContext, did)\n if (!didRecord) {\n throw new CredoError('DidRecord not found')\n }\n\n if (!didRecord.didDocument?.verificationMethod) {\n throw new CredoError('VerificationMethod not found cannot get public key')\n }\n\n const publicKeyBase58 = didRecord.didDocument.verificationMethod[0].publicKeyBase58\n\n return publicKeyBase58\n }\n\n public updateModuleConfig({\n didRegistrarContractAddress,\n fileServerToken,\n rpcUrl,\n schemaManagerContractAddress,\n serverUrl,\n }: SchemaRegistryConfig) {\n this.rpcUrl = rpcUrl\n this.didContractAddress = didRegistrarContractAddress\n this.schemaManagerContractAddress = schemaManagerContractAddress\n this.fileServerToken = fileServerToken\n this.fileServerUrl = serverUrl\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAyCA,IAAY,sDAAL;AACL;AACA;AACA;AACA;;;AAgBF,IAAY,4DAAL;AACL;;;AAIK,iCAAM,qBAAqB;CAOhC,AAAO,YAAY,EACjB,oBACA,QACA,iBACA,8BACA,aACsB;AACtB,OAAK,SAAS;AACd,OAAK,qBAAqB;AAC1B,OAAK,+BAA+B;AACpC,OAAK,kBAAkB;AACvB,OAAK,gBAAgB;;CAGvB,MAAa,aACX,cACA,EAAE,KAAK,YAAY,UACnB;EACA,MAAM,kBAAkB,MAAM,KAAK,oBAAoB,cAAc,IAAI;AAEzE,MAAI,CAAC,gBACH,OAAM,IAAI,WAAW,iCAAiC;EAGxD,MAAM,aAAa,MAAM,KAAK,cAAc,cAAc,gBAAgB;EAE1E,MAAM,iBAAiB,KAAK,6BAA6B,WAAW;AAEp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AGT,MAAc,oBAAoB,cAA4B,KAAa;EAGzE,MAAM,YAAY,MAFI,aAAa,kBAAkB,QAAQ,cAAc,CAErC,eAAe,cAAc,IAAI;AACvE,MAAI,CAAC,UACH,OAAM,IAAI,WAAW,sBAAsB;AAG7C,MAAI,CAAC,UAAU,aAAa,mBAC1B,OAAM,IAAI,WAAW,qDAAqD;AAK5E,SAFwB,UAAU,YAAY,mBAAmB,GAAG;;CAKtE,AAAO,mBAAmB,EACxB,6BACA,iBACA,QACA,8BACA,aACuB;AACvB,OAAK,SAAS;AACd,OAAK,qBAAqB;AAC1B,OAAK,+BAA+B;AACpC,OAAK,kBAAkB;AACvB,OAAK,gBAAgB;;;mCAnQxB,YAAY"}
@@ -1 +1 @@
1
- import { generateSecp256k1KeyPair, getSecp256k1DidDocWithPublicKey } from "./utils.mjs";
1
+ import { generateSecp256k1KeyPair, getCompressedEcdsaSecp256k1VerificationKey2019, getSecp256k1DidDocWithPublicKey } from "./utils.mjs";
@@ -1 +1 @@
1
- import { generateSecp256k1KeyPair, getSecp256k1DidDocWithPublicKey } from "./utils.mjs";
1
+ import { generateSecp256k1KeyPair, getCompressedEcdsaSecp256k1VerificationKey2019, getSecp256k1DidDocWithPublicKey } from "./utils.mjs";
@@ -1,4 +1,5 @@
1
- import { DidDocument } from "@credo-ts/core";
1
+ import { DidDocument, VerificationMethod } from "@credo-ts/core";
2
+ import { PublicJwk, Secp256k1PublicJwk } from "@credo-ts/core/kms";
2
3
 
3
4
  //#region src/utils/utils.d.ts
4
5
  declare const generateSecp256k1KeyPair: () => Promise<{
@@ -7,6 +8,18 @@ declare const generateSecp256k1KeyPair: () => Promise<{
7
8
  address: string;
8
9
  }>;
9
10
  declare function getSecp256k1DidDocWithPublicKey(did: string, publicKeyBase58: string, serviceEndpoint?: string): DidDocument;
11
+ /**
12
+ * Get a EcdsaSecp256k1VerificationKey2019 verification method with a compressed public key.
13
+ */
14
+ declare function getCompressedEcdsaSecp256k1VerificationKey2019({
15
+ publicJwk,
16
+ id,
17
+ controller
18
+ }: {
19
+ id: string;
20
+ publicJwk: PublicJwk<Secp256k1PublicJwk>;
21
+ controller: string;
22
+ }): VerificationMethod;
10
23
  //#endregion
11
- export { generateSecp256k1KeyPair, getSecp256k1DidDocWithPublicKey };
24
+ export { generateSecp256k1KeyPair, getCompressedEcdsaSecp256k1VerificationKey2019, getSecp256k1DidDocWithPublicKey };
12
25
  //# sourceMappingURL=utils.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/utils/utils.ts"],"mappings":";;;cAWa,wBAAA,QAAwB,OAAA;;;;;iBAKrB,+BAAA,CACd,GAAA,UACA,eAAA,UACA,eAAA,YACC,WAAA"}
1
+ {"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/utils/utils.ts"],"mappings":";;;;cAYa,wBAAA,QAAwB,OAAA;;;;;iBAKrB,+BAAA,CACd,GAAA,UACA,eAAA,UACA,eAAA,YACC,WAAA;;;;iBAmCa,8CAAA,CAAA;EACd,SAAA;EACA,EAAA;EACA;AAAA;EAEA,EAAA;EACA,SAAA,EAAW,SAAA,CAAU,kBAAA;EACrB,UAAA;AAAA,IACD,kBAAA"}
@@ -1,6 +1,6 @@
1
1
  import { SECURITY_CONTEXT_SECP256k1_URL } from "../signature-suites/EcdsaSecp256k1Signature2019.mjs";
2
2
  import "../signature-suites/index.mjs";
3
- import { DidDocumentBuilder, DidDocumentService, VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019, VerificationMethod } from "@credo-ts/core";
3
+ import { DidDocumentBuilder, DidDocumentService, TypedArrayEncoder, VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019, VerificationMethod } from "@credo-ts/core";
4
4
  import { PolygonDID } from "@ayanworks/polygon-did-registrar";
5
5
 
6
6
  //#region src/utils/utils.ts
@@ -33,7 +33,18 @@ function getSecp256k1DidDocWithPublicKey(did, publicKeyBase58, serviceEndpoint)
33
33
  didDocumentBuilder.addKeyAgreement(verificationMethod.id);
34
34
  return didDocumentBuilder.build();
35
35
  }
36
+ /**
37
+ * Get a EcdsaSecp256k1VerificationKey2019 verification method with a compressed public key.
38
+ */
39
+ function getCompressedEcdsaSecp256k1VerificationKey2019({ publicJwk, id, controller }) {
40
+ return new VerificationMethod({
41
+ id,
42
+ type: VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019,
43
+ controller,
44
+ publicKeyBase58: TypedArrayEncoder.toBase58(publicJwk.compressedPublicKey.publicKey)
45
+ });
46
+ }
36
47
 
37
48
  //#endregion
38
- export { generateSecp256k1KeyPair, getSecp256k1DidDocWithPublicKey };
49
+ export { generateSecp256k1KeyPair, getCompressedEcdsaSecp256k1VerificationKey2019, getSecp256k1DidDocWithPublicKey };
39
50
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","names":[],"sources":["../../src/utils/utils.ts"],"sourcesContent":["import { PolygonDID } from '@ayanworks/polygon-did-registrar'\nimport type { DidDocument } from '@credo-ts/core'\nimport {\n DidDocumentBuilder,\n DidDocumentService,\n VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019,\n VerificationMethod,\n} from '@credo-ts/core'\n\nimport { SECURITY_CONTEXT_SECP256k1_URL } from '../signature-suites'\n\nexport const generateSecp256k1KeyPair = async () => {\n const { privateKey, publicKeyBase58, address } = await PolygonDID.createKeyPair('testnet')\n return { privateKey, publicKeyBase58, address }\n}\n\nexport function getSecp256k1DidDocWithPublicKey(\n did: string,\n publicKeyBase58: string,\n serviceEndpoint?: string\n): DidDocument {\n const verificationMethod = new VerificationMethod({\n id: `${did}#key-1`,\n type: VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019,\n controller: did,\n publicKeyBase58,\n })\n\n const didDocumentBuilder = new DidDocumentBuilder(did)\n didDocumentBuilder.addContext(SECURITY_CONTEXT_SECP256k1_URL).addVerificationMethod(verificationMethod)\n\n if (serviceEndpoint) {\n const service = new DidDocumentService({\n id: `${did}#linked-domain`,\n serviceEndpoint,\n type: 'LinkedDomains',\n })\n\n didDocumentBuilder.addService(service)\n }\n\n didDocumentBuilder\n .addAuthentication(verificationMethod.id)\n .addAssertionMethod(verificationMethod.id)\n .addCapabilityDelegation(verificationMethod.id)\n .addCapabilityInvocation(verificationMethod.id)\n\n didDocumentBuilder.addKeyAgreement(verificationMethod.id)\n\n return didDocumentBuilder.build()\n}\n"],"mappings":";;;;;;AAWA,MAAa,2BAA2B,YAAY;CAClD,MAAM,EAAE,YAAY,iBAAiB,YAAY,MAAM,WAAW,cAAc,UAAU;AAC1F,QAAO;EAAE;EAAY;EAAiB;EAAS;;AAGjD,SAAgB,gCACd,KACA,iBACA,iBACa;CACb,MAAM,qBAAqB,IAAI,mBAAmB;EAChD,IAAI,GAAG,IAAI;EACX,MAAM;EACN,YAAY;EACZ;EACD,CAAC;CAEF,MAAM,qBAAqB,IAAI,mBAAmB,IAAI;AACtD,oBAAmB,WAAW,+BAA+B,CAAC,sBAAsB,mBAAmB;AAEvG,KAAI,iBAAiB;EACnB,MAAM,UAAU,IAAI,mBAAmB;GACrC,IAAI,GAAG,IAAI;GACX;GACA,MAAM;GACP,CAAC;AAEF,qBAAmB,WAAW,QAAQ;;AAGxC,oBACG,kBAAkB,mBAAmB,GAAG,CACxC,mBAAmB,mBAAmB,GAAG,CACzC,wBAAwB,mBAAmB,GAAG,CAC9C,wBAAwB,mBAAmB,GAAG;AAEjD,oBAAmB,gBAAgB,mBAAmB,GAAG;AAEzD,QAAO,mBAAmB,OAAO"}
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../../src/utils/utils.ts"],"sourcesContent":["import { PolygonDID } from '@ayanworks/polygon-did-registrar'\nimport type { DidDocument } from '@credo-ts/core'\nimport {\n DidDocumentBuilder,\n DidDocumentService,\n TypedArrayEncoder,\n VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019,\n VerificationMethod,\n} from '@credo-ts/core'\nimport type { PublicJwk, Secp256k1PublicJwk } from '@credo-ts/core/kms'\nimport { SECURITY_CONTEXT_SECP256k1_URL } from '../signature-suites'\n\nexport const generateSecp256k1KeyPair = async () => {\n const { privateKey, publicKeyBase58, address } = await PolygonDID.createKeyPair('testnet')\n return { privateKey, publicKeyBase58, address }\n}\n\nexport function getSecp256k1DidDocWithPublicKey(\n did: string,\n publicKeyBase58: string,\n serviceEndpoint?: string\n): DidDocument {\n const verificationMethod = new VerificationMethod({\n id: `${did}#key-1`,\n type: VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019,\n controller: did,\n publicKeyBase58,\n })\n\n const didDocumentBuilder = new DidDocumentBuilder(did)\n didDocumentBuilder.addContext(SECURITY_CONTEXT_SECP256k1_URL).addVerificationMethod(verificationMethod)\n\n if (serviceEndpoint) {\n const service = new DidDocumentService({\n id: `${did}#linked-domain`,\n serviceEndpoint,\n type: 'LinkedDomains',\n })\n\n didDocumentBuilder.addService(service)\n }\n\n didDocumentBuilder\n .addAuthentication(verificationMethod.id)\n .addAssertionMethod(verificationMethod.id)\n .addCapabilityDelegation(verificationMethod.id)\n .addCapabilityInvocation(verificationMethod.id)\n\n didDocumentBuilder.addKeyAgreement(verificationMethod.id)\n\n return didDocumentBuilder.build()\n}\n\n/**\n * Get a EcdsaSecp256k1VerificationKey2019 verification method with a compressed public key.\n */\nexport function getCompressedEcdsaSecp256k1VerificationKey2019({\n publicJwk,\n id,\n controller,\n}: {\n id: string\n publicJwk: PublicJwk<Secp256k1PublicJwk>\n controller: string\n}) {\n return new VerificationMethod({\n id,\n type: VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019,\n controller,\n publicKeyBase58: TypedArrayEncoder.toBase58(publicJwk.compressedPublicKey.publicKey),\n })\n}\n"],"mappings":";;;;;;AAYA,MAAa,2BAA2B,YAAY;CAClD,MAAM,EAAE,YAAY,iBAAiB,YAAY,MAAM,WAAW,cAAc,UAAU;AAC1F,QAAO;EAAE;EAAY;EAAiB;EAAS;;AAGjD,SAAgB,gCACd,KACA,iBACA,iBACa;CACb,MAAM,qBAAqB,IAAI,mBAAmB;EAChD,IAAI,GAAG,IAAI;EACX,MAAM;EACN,YAAY;EACZ;EACD,CAAC;CAEF,MAAM,qBAAqB,IAAI,mBAAmB,IAAI;AACtD,oBAAmB,WAAW,+BAA+B,CAAC,sBAAsB,mBAAmB;AAEvG,KAAI,iBAAiB;EACnB,MAAM,UAAU,IAAI,mBAAmB;GACrC,IAAI,GAAG,IAAI;GACX;GACA,MAAM;GACP,CAAC;AAEF,qBAAmB,WAAW,QAAQ;;AAGxC,oBACG,kBAAkB,mBAAmB,GAAG,CACxC,mBAAmB,mBAAmB,GAAG,CACzC,wBAAwB,mBAAmB,GAAG,CAC9C,wBAAwB,mBAAmB,GAAG;AAEjD,oBAAmB,gBAAgB,mBAAmB,GAAG;AAEzD,QAAO,mBAAmB,OAAO;;;;;AAMnC,SAAgB,+CAA+C,EAC7D,WACA,IACA,cAKC;AACD,QAAO,IAAI,mBAAmB;EAC5B;EACA,MAAM;EACN;EACA,iBAAiB,kBAAkB,SAAS,UAAU,oBAAoB,UAAU;EACrF,CAAC"}
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "@ayanworks/credo-polygon-w3c-module",
3
- "version": "2.0.1",
3
+ "version": "2.0.2-alpha-20260313061926",
4
4
  "files": [
5
5
  "build"
6
6
  ],
7
+ "exports": {
8
+ ".": {
9
+ "require": "./build/index.mjs",
10
+ "import": "./build/index.d.mts"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
7
14
  "license": "Apache-2.0",
8
15
  "publishConfig": {
9
16
  "access": "public"
@@ -17,11 +24,11 @@
17
24
  "dependencies": {
18
25
  "@credo-ts/askar": "^0.6.1",
19
26
  "@credo-ts/core": "^0.6.1",
20
- "@ayanworks/polygon-did-registrar": "2.2.0",
21
- "@ayanworks/polygon-did-resolver": "1.0.2",
22
- "@ayanworks/polygon-schema-manager": "2.2.0",
23
27
  "did-resolver": "^4.1.0",
24
- "ethers": "^6.16.0"
28
+ "ethers": "^6.16.0",
29
+ "@ayanworks/polygon-did-registrar": "2.2.1-alpha-20260313061926",
30
+ "@ayanworks/polygon-did-resolver": "1.0.3-alpha-20260313061926",
31
+ "@ayanworks/polygon-schema-manager": "2.2.1-alpha-20260313061926"
25
32
  },
26
33
  "devDependencies": {
27
34
  "@credo-ts/node": "^0.6.1",
@@ -35,12 +42,9 @@
35
42
  },
36
43
  "scripts": {
37
44
  "build": "tsdown --config-loader unconfig",
45
+ "clean": "rm -rf build",
38
46
  "test": "vitest run"
39
47
  },
40
48
  "types": "./build/index.d.mts",
41
- "module": "./build/index.mjs",
42
- "exports": {
43
- ".": "./build/index.mjs",
44
- "./package.json": "./package.json"
45
- }
49
+ "module": "./build/index.mjs"
46
50
  }