@ayanworks/credo-polygon-w3c-module 2.0.2-alpha-20260310100644 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/PolygonModule.mjs +1 -1
- package/build/dids/PolygonDidRegistrar.d.mts.map +1 -1
- package/build/dids/PolygonDidRegistrar.mjs +10 -4
- package/build/dids/PolygonDidRegistrar.mjs.map +1 -1
- package/build/dids/didPolygonUtil.mjs +4 -2
- package/build/dids/didPolygonUtil.mjs.map +1 -1
- package/build/index.d.mts +2 -2
- package/build/index.mjs +3 -3
- package/build/ledger/PolygonLedgerService.mjs +2 -2
- package/build/utils/index.d.mts +1 -1
- package/build/utils/index.mjs +1 -1
- package/build/utils/utils.d.mts +15 -2
- package/build/utils/utils.d.mts.map +1 -1
- package/build/utils/utils.mjs +13 -2
- package/build/utils/utils.mjs.map +1 -1
- package/package.json +8 -6
package/build/PolygonModule.mjs
CHANGED
|
@@ -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";
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,8 +1,10 @@
|
|
|
1
|
+
import { getCompressedEcdsaSecp256k1VerificationKey2019 } from "../utils/utils.mjs";
|
|
2
|
+
import "../utils/index.mjs";
|
|
1
3
|
import { buildDid, createSecp256k1PublicJwk, getSecp256k1DidDoc, validateSpecCompliantPayload } from "./didPolygonUtil.mjs";
|
|
2
4
|
import { PolygonModuleConfig } from "../PolygonModuleConfig.mjs";
|
|
3
5
|
import { PolygonLedgerService } from "../ledger/PolygonLedgerService.mjs";
|
|
4
6
|
import "../ledger/index.mjs";
|
|
5
|
-
import { Buffer, CredoError, DidDocument, DidDocumentBuilder, DidDocumentRole, DidRecord, DidRepository, JsonTransformer, TypedArrayEncoder
|
|
7
|
+
import { Buffer, CredoError, DidDocument, DidDocumentBuilder, DidDocumentRole, DidRecord, DidRepository, JsonTransformer, TypedArrayEncoder } from "@credo-ts/core";
|
|
6
8
|
import { KeyManagementApi, KeyManagementKeyNotFoundError } from "@credo-ts/core/kms";
|
|
7
9
|
import { JsonRpcProvider, SigningKey, Wallet } from "ethers";
|
|
8
10
|
import { getResolver } from "@ayanworks/polygon-did-resolver";
|
|
@@ -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);
|
|
@@ -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 =
|
|
151
|
+
const verificationMethod = getCompressedEcdsaSecp256k1VerificationKey2019({
|
|
146
152
|
id: `${didDocument.id}#key-${verificationMethodCount + 1}`,
|
|
147
153
|
publicJwk: secp256k1Jwk,
|
|
148
154
|
controller: didDocument.id
|
|
@@ -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 { PolygonModuleConfig } from '../PolygonModuleConfig'\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 } = 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._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 = 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._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}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e,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
|
+
{"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,SAAO;GAAE;GAAiB;GAAW;GAAO;;CAG9C,MAAa,OAAO,cAA4B,SAA4D;EAC1G,MAAM,gBAAgB,aAAa,kBAAkB,QAAQ,qBAAqB;EAClF,MAAM,gBAAgB,aAAa,kBAAkB,QAAQ,cAAc;EAE3E,MAAM,aAAa,QAAQ,OA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M,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,5 +1,7 @@
|
|
|
1
1
|
import { SECURITY_CONTEXT_SECP256k1_URL } from "../signature-suites/EcdsaSecp256k1Signature2019.mjs";
|
|
2
|
-
import {
|
|
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 =
|
|
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
|
|
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 };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { PolygonModuleConfig } from "../PolygonModuleConfig.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
|
package/build/utils/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import { generateSecp256k1KeyPair, getSecp256k1DidDocWithPublicKey } from "./utils.mjs";
|
|
1
|
+
import { generateSecp256k1KeyPair, getCompressedEcdsaSecp256k1VerificationKey2019, getSecp256k1DidDocWithPublicKey } from "./utils.mjs";
|
package/build/utils/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import { generateSecp256k1KeyPair, getSecp256k1DidDocWithPublicKey } from "./utils.mjs";
|
|
1
|
+
import { generateSecp256k1KeyPair, getCompressedEcdsaSecp256k1VerificationKey2019, getSecp256k1DidDocWithPublicKey } from "./utils.mjs";
|
package/build/utils/utils.d.mts
CHANGED
|
@@ -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":"
|
|
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"}
|
package/build/utils/utils.mjs
CHANGED
|
@@ -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'\
|
|
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,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ayanworks/credo-polygon-w3c-module",
|
|
3
|
-
"version": "2.0.2
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"files": [
|
|
5
5
|
"build"
|
|
6
6
|
],
|
|
7
7
|
"exports": {
|
|
8
|
-
"
|
|
9
|
-
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./build/index.mjs",
|
|
10
|
+
"import": "./build/index.d.mts"
|
|
11
|
+
},
|
|
10
12
|
"./package.json": "./package.json"
|
|
11
13
|
},
|
|
12
14
|
"license": "Apache-2.0",
|
|
@@ -24,9 +26,9 @@
|
|
|
24
26
|
"@credo-ts/core": "^0.6.1",
|
|
25
27
|
"did-resolver": "^4.1.0",
|
|
26
28
|
"ethers": "^6.16.0",
|
|
27
|
-
"@ayanworks/polygon-did-registrar": "2.2.1
|
|
28
|
-
"@ayanworks/polygon-did-resolver": "1.0.3
|
|
29
|
-
"@ayanworks/polygon-schema-manager": "2.2.1
|
|
29
|
+
"@ayanworks/polygon-did-registrar": "2.2.1",
|
|
30
|
+
"@ayanworks/polygon-did-resolver": "1.0.3",
|
|
31
|
+
"@ayanworks/polygon-schema-manager": "2.2.1"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
34
|
"@credo-ts/node": "^0.6.1",
|