@bhutan-ndi/ethr-credo-module 0.0.0-20251226085115

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.
Files changed (58) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +31 -0
  3. package/build/EthereumApi.d.ts +13 -0
  4. package/build/EthereumApi.js +34 -0
  5. package/build/EthereumApi.js.map +1 -0
  6. package/build/EthereumModule.d.ts +10 -0
  7. package/build/EthereumModule.js +31 -0
  8. package/build/EthereumModule.js.map +1 -0
  9. package/build/EthereumModuleConfig.d.ts +19 -0
  10. package/build/EthereumModuleConfig.js +14 -0
  11. package/build/EthereumModuleConfig.js.map +1 -0
  12. package/build/abi/SchemaRegistry.json +136 -0
  13. package/build/dids/EthrDidRegistrar.d.ts +28 -0
  14. package/build/dids/EthrDidRegistrar.js +69 -0
  15. package/build/dids/EthrDidRegistrar.js.map +1 -0
  16. package/build/dids/EthrDidResolver.d.ts +6 -0
  17. package/build/dids/EthrDidResolver.js +36 -0
  18. package/build/dids/EthrDidResolver.js.map +1 -0
  19. package/build/dids/didEthrUtil.d.ts +5 -0
  20. package/build/dids/didEthrUtil.js +52 -0
  21. package/build/dids/didEthrUtil.js.map +1 -0
  22. package/build/dids/index.d.ts +3 -0
  23. package/build/dids/index.js +20 -0
  24. package/build/dids/index.js.map +1 -0
  25. package/build/index.d.ts +5 -0
  26. package/build/index.js +28 -0
  27. package/build/index.js.map +1 -0
  28. package/build/ledger/EthereumLedgerService.d.ts +42 -0
  29. package/build/ledger/EthereumLedgerService.js +250 -0
  30. package/build/ledger/EthereumLedgerService.js.map +1 -0
  31. package/build/ledger/index.d.ts +1 -0
  32. package/build/ledger/index.js +18 -0
  33. package/build/ledger/index.js.map +1 -0
  34. package/build/schema/EthereumSchemaRegistry.d.ts +37 -0
  35. package/build/schema/EthereumSchemaRegistry.js +174 -0
  36. package/build/schema/EthereumSchemaRegistry.js.map +1 -0
  37. package/build/schema/types/EthereumSchemaRegistry.types.d.ts +33 -0
  38. package/build/schema/types/EthereumSchemaRegistry.types.js +36 -0
  39. package/build/schema/types/EthereumSchemaRegistry.types.js.map +1 -0
  40. package/build/signature-suites/EcdsaSecp256k1RecoveryMethod2020.d.ts +60 -0
  41. package/build/signature-suites/EcdsaSecp256k1RecoveryMethod2020.js +126 -0
  42. package/build/signature-suites/EcdsaSecp256k1RecoveryMethod2020.js.map +1 -0
  43. package/build/signature-suites/EcdsaSecp256k1Signature2019.d.ts +60 -0
  44. package/build/signature-suites/EcdsaSecp256k1Signature2019.js +126 -0
  45. package/build/signature-suites/EcdsaSecp256k1Signature2019.js.map +1 -0
  46. package/build/signature-suites/index.d.ts +2 -0
  47. package/build/signature-suites/index.js +19 -0
  48. package/build/signature-suites/index.js.map +1 -0
  49. package/build/utils/index.d.ts +1 -0
  50. package/build/utils/index.js +18 -0
  51. package/build/utils/index.js.map +1 -0
  52. package/build/utils/schemaHelper.d.ts +20 -0
  53. package/build/utils/schemaHelper.js +64 -0
  54. package/build/utils/schemaHelper.js.map +1 -0
  55. package/build/utils/utils.d.ts +11 -0
  56. package/build/utils/utils.js +69 -0
  57. package/build/utils/utils.js.map +1 -0
  58. package/package.json +66 -0
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EthereumSchemaRegistry = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const SchemaRegistry_json_1 = __importDefault(require("../abi/SchemaRegistry.json"));
9
+ const EthereumSchemaRegistry_types_1 = require("./types/EthereumSchemaRegistry.types");
10
+ class EthereumSchemaRegistry {
11
+ constructor(config) {
12
+ this.validateConfig(config);
13
+ try {
14
+ this.provider = new ethers_1.JsonRpcProvider(config.rpcUrl);
15
+ if (config.signingKey) {
16
+ this.wallet = new ethers_1.Wallet(config.signingKey, this.provider);
17
+ this.schemaRegistryContract = new ethers_1.Contract(config.contractAddress, SchemaRegistry_json_1.default, this.wallet);
18
+ }
19
+ else {
20
+ this.schemaRegistryContract = new ethers_1.Contract(config.contractAddress, SchemaRegistry_json_1.default, this.provider);
21
+ }
22
+ }
23
+ catch (error) {
24
+ throw new EthereumSchemaRegistry_types_1.NetworkError(`Failed to initialize EthereumSchemaManager: ${error instanceof Error ? error.message : 'Unknown error'}`, error);
25
+ }
26
+ }
27
+ validateConfig(config) {
28
+ if (!config.contractAddress || !(0, ethers_1.isAddress)(config.contractAddress)) {
29
+ throw new EthereumSchemaRegistry_types_1.ValidationError('Invalid contract address');
30
+ }
31
+ if (!config.rpcUrl) {
32
+ throw new EthereumSchemaRegistry_types_1.ValidationError('RPC URL is required');
33
+ }
34
+ }
35
+ /**
36
+ * Create a new schema (requires wallet)
37
+ */
38
+ async createSchema(schemaId, json) {
39
+ if (!this.wallet) {
40
+ throw new EthereumSchemaRegistry_types_1.ValidationError('Wallet is required for transaction operations');
41
+ }
42
+ this.validateSchemaId(schemaId);
43
+ this.validateJson(json);
44
+ try {
45
+ const schemaTxn = await this.schemaRegistryContract.createSchema(schemaId, json);
46
+ const schemaTxnReceipt = await schemaTxn.wait();
47
+ return schemaTxnReceipt;
48
+ }
49
+ catch (error) {
50
+ return await this.handleContractError(error);
51
+ }
52
+ }
53
+ /**
54
+ * Create a schema for another address (admin only, requires wallet)
55
+ */
56
+ async adminCreateSchema(address, schemaId, json) {
57
+ if (!this.wallet) {
58
+ throw new EthereumSchemaRegistry_types_1.ValidationError('Wallet is required for transaction operations');
59
+ }
60
+ this.validateAddress(address);
61
+ this.validateSchemaId(schemaId);
62
+ this.validateJson(json);
63
+ try {
64
+ const schemaTxn = await this.schemaRegistryContract.adminCreateSchema(address, schemaId, json);
65
+ const schemaTxnReceipt = await schemaTxn.wait();
66
+ return schemaTxnReceipt;
67
+ }
68
+ catch (error) {
69
+ return await this.handleContractError(error);
70
+ }
71
+ }
72
+ /**
73
+ * Get a schema by owner address and schema ID
74
+ */
75
+ async getSchemaById(address, schemaId) {
76
+ this.validateAddress(address);
77
+ this.validateSchemaId(schemaId);
78
+ try {
79
+ const schema = await this.schemaRegistryContract.schemas(address, schemaId);
80
+ if (!schema || schema.trim().length === 0) {
81
+ return null;
82
+ }
83
+ return schema;
84
+ }
85
+ catch (error) {
86
+ return await this.handleContractError(error);
87
+ }
88
+ }
89
+ /**
90
+ * Get list of schema Id by address
91
+ */
92
+ async getSchemaIds(address) {
93
+ this.validateAddress(address);
94
+ try {
95
+ const schemaIds = await this.schemaRegistryContract.getSchemaIds(address);
96
+ return schemaIds;
97
+ }
98
+ catch (error) {
99
+ return await this.handleContractError(error);
100
+ }
101
+ }
102
+ /**
103
+ * Get the current contract owner
104
+ */
105
+ async getOwner() {
106
+ try {
107
+ const owner = await this.schemaRegistryContract.owner();
108
+ return owner;
109
+ }
110
+ catch (error) {
111
+ return await this.handleContractError(error);
112
+ }
113
+ }
114
+ /**
115
+ * Transfer contract ownership (admin only, requires wallet)
116
+ */
117
+ async transferOwnership(newOwner) {
118
+ if (!this.wallet) {
119
+ throw new EthereumSchemaRegistry_types_1.ValidationError('Wallet is required for transaction operations');
120
+ }
121
+ this.validateAddress(newOwner);
122
+ try {
123
+ const tx = await this.schemaRegistryContract.transferOwnership(newOwner);
124
+ const receipt = await tx.wait();
125
+ return receipt;
126
+ }
127
+ catch (error) {
128
+ return await this.handleContractError(error);
129
+ }
130
+ }
131
+ validateSchemaId(schemaId) {
132
+ if (!schemaId || schemaId.trim().length === 0) {
133
+ throw new EthereumSchemaRegistry_types_1.ValidationError('Schema ID cannot be empty');
134
+ }
135
+ if (schemaId.length > 256) {
136
+ throw new EthereumSchemaRegistry_types_1.ValidationError('Schema ID too long (max 256 characters)');
137
+ }
138
+ }
139
+ validateJson(json) {
140
+ if (!json || json.trim().length === 0) {
141
+ throw new EthereumSchemaRegistry_types_1.ValidationError('JSON cannot be empty');
142
+ }
143
+ try {
144
+ JSON.parse(json);
145
+ }
146
+ catch (_a) {
147
+ throw new EthereumSchemaRegistry_types_1.ValidationError('Invalid JSON format');
148
+ }
149
+ }
150
+ validateAddress(address) {
151
+ if (!address || !(0, ethers_1.isAddress)(address)) {
152
+ throw new EthereumSchemaRegistry_types_1.ValidationError('Invalid address');
153
+ }
154
+ }
155
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
156
+ async handleContractError(error) {
157
+ if (error.reason) {
158
+ switch (error.reason) {
159
+ case 'SCHEMA_EXISTS':
160
+ throw new EthereumSchemaRegistry_types_1.ContractError('Schema already exists for this address and schema ID', error.reason, error);
161
+ case 'NOT_OWNER':
162
+ throw new EthereumSchemaRegistry_types_1.ContractError('Only contract owner can perform this action', error.reason, error);
163
+ default:
164
+ throw new EthereumSchemaRegistry_types_1.ContractError(`Contract error: ${error.reason}`, error.reason, error);
165
+ }
166
+ }
167
+ if (error.code === 'NETWORK_ERROR') {
168
+ throw new EthereumSchemaRegistry_types_1.NetworkError(`Network error: ${error.message}`, error);
169
+ }
170
+ throw new EthereumSchemaRegistry_types_1.ContractError(`Transaction failed: ${error.message}`, undefined, error);
171
+ }
172
+ }
173
+ exports.EthereumSchemaRegistry = EthereumSchemaRegistry;
174
+ //# sourceMappingURL=EthereumSchemaRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EthereumSchemaRegistry.js","sourceRoot":"","sources":["../../src/schema/EthereumSchemaRegistry.ts"],"names":[],"mappings":";;;;;;AAGA,mCAAqE;AAErE,qFAA4C;AAE5C,uFAAmG;AAEnG,MAAa,sBAAsB;IAKjC,YAAmB,MAA4B;QAC7C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QAE3B,IAAI;YACF,IAAI,CAAC,QAAQ,GAAG,IAAI,wBAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAElD,IAAI,MAAM,CAAC,UAAU,EAAE;gBACrB,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI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,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAA;SACjE;QAED,MAAM,IAAI,4CAAa,CAAC,uBAAuB,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;IACnF,CAAC;CACF;AAtLD,wDAsLC"}
@@ -0,0 +1,33 @@
1
+ import type { SigningKey } from 'ethers';
2
+ export interface SchemaRegistryConfig {
3
+ contractAddress: string;
4
+ rpcUrl: string;
5
+ signingKey?: SigningKey;
6
+ }
7
+ export declare class SchemaRegistryError extends Error {
8
+ code?: string | undefined;
9
+ originalError?: Error | undefined;
10
+ constructor(message: string, code?: string | undefined, originalError?: Error | undefined);
11
+ }
12
+ export declare class ContractError extends SchemaRegistryError {
13
+ revertReason?: string | undefined;
14
+ constructor(message: string, revertReason?: string | undefined, originalError?: Error);
15
+ }
16
+ export declare class NetworkError extends SchemaRegistryError {
17
+ constructor(message: string, originalError?: Error);
18
+ }
19
+ export declare class ValidationError extends SchemaRegistryError {
20
+ constructor(message: string, originalError?: Error);
21
+ }
22
+ export type ResourcePayload = {
23
+ resourceURI: string;
24
+ resourceCollectionId: string;
25
+ resourceId: string;
26
+ resourceName: string;
27
+ resourceType: string;
28
+ mediaType: string;
29
+ created: string;
30
+ checksum: string;
31
+ previousVersionId: string | null;
32
+ nextVersionId: string | null;
33
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationError = exports.NetworkError = exports.ContractError = exports.SchemaRegistryError = void 0;
4
+ // Custom error classes
5
+ class SchemaRegistryError extends Error {
6
+ constructor(message, code, originalError) {
7
+ super(message);
8
+ this.code = code;
9
+ this.originalError = originalError;
10
+ this.name = 'SchemaRegistryError';
11
+ }
12
+ }
13
+ exports.SchemaRegistryError = SchemaRegistryError;
14
+ class ContractError extends SchemaRegistryError {
15
+ constructor(message, revertReason, originalError) {
16
+ super(message, 'CONTRACT_ERROR', originalError);
17
+ this.revertReason = revertReason;
18
+ this.name = 'ContractError';
19
+ }
20
+ }
21
+ exports.ContractError = ContractError;
22
+ class NetworkError extends SchemaRegistryError {
23
+ constructor(message, originalError) {
24
+ super(message, 'NETWORK_ERROR', originalError);
25
+ this.name = 'NetworkError';
26
+ }
27
+ }
28
+ exports.NetworkError = NetworkError;
29
+ class ValidationError extends SchemaRegistryError {
30
+ constructor(message, originalError) {
31
+ super(message, 'VALIDATION_ERROR', originalError);
32
+ this.name = 'ValidationError';
33
+ }
34
+ }
35
+ exports.ValidationError = ValidationError;
36
+ //# sourceMappingURL=EthereumSchemaRegistry.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EthereumSchemaRegistry.types.js","sourceRoot":"","sources":["../../../src/schema/types/EthereumSchemaRegistry.types.ts"],"names":[],"mappings":";;;AAQA,uBAAuB;AACvB,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAmB,OAAe,EAAS,IAAa,EAAS,aAAqB;QACpF,KAAK,CAAC,OAAO,CAAC,CAAA;QAD2B,SAAI,GAAJ,IAAI,CAAS;QAAS,kBAAa,GAAb,aAAa,CAAQ;QAEpF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;AALD,kDAKC;AAED,MAAa,aAAc,SAAQ,mBAAmB;IACpD,YAAmB,OAAe,EAAS,YAAqB,EAAE,aAAqB;QACrF,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAAA;QADN,iBAAY,GAAZ,YAAY,CAAS;QAE9D,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;IAC7B,CAAC;CACF;AALD,sCAKC;AAED,MAAa,YAAa,SAAQ,mBAAmB;IACnD,YAAmB,OAAe,EAAE,aAAqB;QACvD,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,aAAa,CAAC,CAAA;QAC9C,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;IAC5B,CAAC;CACF;AALD,oCAKC;AAED,MAAa,eAAgB,SAAQ,mBAAmB;IACtD,YAAmB,OAAe,EAAE,aAAqB;QACvD,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,aAAa,CAAC,CAAA;QACjD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;IAC/B,CAAC;CACF;AALD,0CAKC"}
@@ -0,0 +1,60 @@
1
+ import type { DocumentLoader, JwsLinkedDataSignatureOptions, Proof } from '@credo-ts/core';
2
+ import type { JsonLdDoc } from '@credo-ts/core/build/modules/vc/data-integrity/jsonldUtil';
3
+ import { JwsLinkedDataSignature } from '@credo-ts/core';
4
+ export declare const SECURITY_CONTEXT_SECP256k1_RECOVERY_URL = "https://w3id.org/security/suites/secp256k1recovery-2020/v2";
5
+ type EcdsaSecp256k1RecoverySignature2020Options = Pick<JwsLinkedDataSignatureOptions, 'key' | 'proof' | 'date' | 'useNativeCanonize' | 'LDKeyClass'>;
6
+ /**
7
+ * A secp256k1 signature suite for use with k251 key pairs
8
+ */
9
+ export declare class EcdsaSecp256k1RecoverySignature2020 extends JwsLinkedDataSignature {
10
+ static CONTEXT_URL: string;
11
+ /**
12
+ * @param {object} options - Options hashmap.
13
+ *
14
+ * Either a `key` OR at least one of `signer`/`verifier` is required.
15
+ *
16
+ * @param {object} [options.key] - An optional key object (containing an
17
+ * `id` property, and either `signer` or `verifier`, depending on the
18
+ * intended operation. Useful for when the application is managing keys
19
+ * itself (when using a KMS, you never have access to the private key,
20
+ * and so should use the `signer` param instead).
21
+ * @param {Function} [options.signer] - Signer function that returns an
22
+ * object with an async sign() method. This is useful when interfacing
23
+ * with a KMS (since you don't get access to the private key and its
24
+ * `signer()`, the KMS client gives you only the signer function to use).
25
+ * @param {Function} [options.verifier] - Verifier function that returns
26
+ * an object with an async `verify()` method. Useful when working with a
27
+ * KMS-provided verifier function.
28
+ *
29
+ * Advanced optional parameters and overrides.
30
+ *
31
+ * @param {object} [options.proof] - A JSON-LD document with options to use
32
+ * for the `proof` node. Any other custom fields can be provided here
33
+ * using a context different from security-v2).
34
+ * @param {string|Date} [options.date] - Signing date to use if not passed.
35
+ * @param {boolean} [options.useNativeCanonize] - Whether to use a native
36
+ * canonize algorithm.
37
+ */
38
+ constructor(options: EcdsaSecp256k1RecoverySignature2020Options);
39
+ assertVerificationMethod(document: JsonLdDoc): Promise<void>;
40
+ getVerificationMethod(options: {
41
+ proof: Proof;
42
+ documentLoader?: DocumentLoader;
43
+ }): Promise<any>;
44
+ /**
45
+ * Ensures the document to be signed contains the required signature suite
46
+ * specific `@context`, by either adding it (if `addSuiteContext` is true),
47
+ * or throwing an error if it's missing.
48
+ *
49
+ * @override
50
+ *
51
+ * @param {object} options - Options hashmap.
52
+ * @param {object} options.document - JSON-LD document to be signed.
53
+ * @param {boolean} options.addSuiteContext - Add suite context?
54
+ */
55
+ ensureSuiteContext(options: {
56
+ document: JsonLdDoc;
57
+ addSuiteContext: boolean;
58
+ }): void;
59
+ }
60
+ export {};
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EcdsaSecp256k1RecoverySignature2020 = exports.SECURITY_CONTEXT_SECP256k1_RECOVERY_URL = void 0;
4
+ const core_1 = require("@credo-ts/core");
5
+ const jsonldUtil_1 = require("@credo-ts/core/build/modules/vc/data-integrity/jsonldUtil");
6
+ const { jsonld } = core_1.vcLibraries;
7
+ exports.SECURITY_CONTEXT_SECP256k1_RECOVERY_URL = 'https://w3id.org/security/suites/secp256k1recovery-2020/v2';
8
+ /**
9
+ * A secp256k1 signature suite for use with k251 key pairs
10
+ */
11
+ class EcdsaSecp256k1RecoverySignature2020 extends core_1.JwsLinkedDataSignature {
12
+ /**
13
+ * @param {object} options - Options hashmap.
14
+ *
15
+ * Either a `key` OR at least one of `signer`/`verifier` is required.
16
+ *
17
+ * @param {object} [options.key] - An optional key object (containing an
18
+ * `id` property, and either `signer` or `verifier`, depending on the
19
+ * intended operation. Useful for when the application is managing keys
20
+ * itself (when using a KMS, you never have access to the private key,
21
+ * and so should use the `signer` param instead).
22
+ * @param {Function} [options.signer] - Signer function that returns an
23
+ * object with an async sign() method. This is useful when interfacing
24
+ * with a KMS (since you don't get access to the private key and its
25
+ * `signer()`, the KMS client gives you only the signer function to use).
26
+ * @param {Function} [options.verifier] - Verifier function that returns
27
+ * an object with an async `verify()` method. Useful when working with a
28
+ * KMS-provided verifier function.
29
+ *
30
+ * Advanced optional parameters and overrides.
31
+ *
32
+ * @param {object} [options.proof] - A JSON-LD document with options to use
33
+ * for the `proof` node. Any other custom fields can be provided here
34
+ * using a context different from security-v2).
35
+ * @param {string|Date} [options.date] - Signing date to use if not passed.
36
+ * @param {boolean} [options.useNativeCanonize] - Whether to use a native
37
+ * canonize algorithm.
38
+ */
39
+ constructor(options) {
40
+ super({
41
+ type: 'EcdsaSecp256k1RecoverySignature2020',
42
+ algorithm: 'EcDSA',
43
+ LDKeyClass: options.LDKeyClass,
44
+ contextUrl: exports.SECURITY_CONTEXT_SECP256k1_RECOVERY_URL,
45
+ key: options.key,
46
+ proof: options.proof,
47
+ date: options.date,
48
+ useNativeCanonize: options.useNativeCanonize,
49
+ });
50
+ this.requiredKeyType = 'EcdsaSecp256k1RecoveryMethod2020';
51
+ }
52
+ async assertVerificationMethod(document) {
53
+ if (!_includesCompatibleContext({ document: document })) {
54
+ // For DID Documents, since keys do not have their own contexts,
55
+ // the suite context is usually provided by the documentLoader logic
56
+ throw new TypeError(`The '@context' of the verification method (key) MUST contain the context url "${this.contextUrl}".`);
57
+ }
58
+ if (!_isSecp256k12019Key(document)) {
59
+ const verificationMethodType = jsonld.getValues(document, 'type')[0];
60
+ throw new Error(`Unsupported verification method type '${verificationMethodType}'. Verification method type MUST be 'EcdsaSecp256k1RecoveryMethod2020'.`);
61
+ }
62
+ else if (_isSecp256k12019Key(document) && !_includesSecp256k12019Context(document)) {
63
+ throw new Error(`For verification method type 'EcdsaSecp256k1RecoveryMethod2020' the '@context' MUST contain the context url "${exports.SECURITY_CONTEXT_SECP256k1_RECOVERY_URL}".`);
64
+ }
65
+ // ensure verification method has not been revoked
66
+ if (document.revoked !== undefined) {
67
+ throw new Error('The verification method has been revoked.');
68
+ }
69
+ }
70
+ async getVerificationMethod(options) {
71
+ const verificationMethod = await super.getVerificationMethod({
72
+ proof: options.proof,
73
+ documentLoader: options.documentLoader,
74
+ });
75
+ return verificationMethod;
76
+ }
77
+ /**
78
+ * Ensures the document to be signed contains the required signature suite
79
+ * specific `@context`, by either adding it (if `addSuiteContext` is true),
80
+ * or throwing an error if it's missing.
81
+ *
82
+ * @override
83
+ *
84
+ * @param {object} options - Options hashmap.
85
+ * @param {object} options.document - JSON-LD document to be signed.
86
+ * @param {boolean} options.addSuiteContext - Add suite context?
87
+ */
88
+ ensureSuiteContext(options) {
89
+ if (_includesCompatibleContext({ document: options.document })) {
90
+ return;
91
+ }
92
+ super.ensureSuiteContext({ document: options.document, addSuiteContext: options.addSuiteContext });
93
+ }
94
+ }
95
+ exports.EcdsaSecp256k1RecoverySignature2020 = EcdsaSecp256k1RecoverySignature2020;
96
+ EcdsaSecp256k1RecoverySignature2020.CONTEXT_URL = exports.SECURITY_CONTEXT_SECP256k1_RECOVERY_URL;
97
+ function _includesCompatibleContext(options) {
98
+ // Handle the EcdsaSecp256k1Signature2019 / credentials/v1 collision
99
+ const hasSecp256k1 = (0, jsonldUtil_1._includesContext)({
100
+ document: options.document,
101
+ contextUrl: exports.SECURITY_CONTEXT_SECP256k1_RECOVERY_URL,
102
+ });
103
+ const hasCred = (0, jsonldUtil_1._includesContext)({ document: options.document, contextUrl: core_1.CREDENTIALS_CONTEXT_V1_URL });
104
+ const hasSecV2 = (0, jsonldUtil_1._includesContext)({ document: options.document, contextUrl: core_1.SECURITY_CONTEXT_URL });
105
+ if (hasSecp256k1 && hasCred) {
106
+ // The secp256k1-2019/v1 and credentials/v1 contexts are incompatible.
107
+ // For VCs using EcdsaSecp256k1Signature2019 suite using the credentials/v1 context is sufficient
108
+ return false;
109
+ }
110
+ if (hasSecp256k1 && hasSecV2) {
111
+ // The secp256k1-2019/v1 and security/v2 contexts are incompatible.
112
+ // For VCs using EcdsaSecp256k1Signature2019 suite, using the security/v2 context is sufficient.
113
+ return false;
114
+ }
115
+ // Either one by itself is fine, for this suite
116
+ return hasSecp256k1 || hasCred || hasSecV2;
117
+ }
118
+ function _isSecp256k12019Key(verificationMethod) {
119
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
120
+ // @ts-ignore - .hasValue is not part of the public API
121
+ return jsonld.hasValue(verificationMethod, 'type', 'EcdsaSecp256k1RecoveryMethod2020');
122
+ }
123
+ function _includesSecp256k12019Context(document) {
124
+ return (0, jsonldUtil_1._includesContext)({ document, contextUrl: exports.SECURITY_CONTEXT_SECP256k1_RECOVERY_URL });
125
+ }
126
+ //# sourceMappingURL=EcdsaSecp256k1RecoveryMethod2020.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EcdsaSecp256k1RecoveryMethod2020.js","sourceRoot":"","sources":["../../src/signature-suites/EcdsaSecp256k1RecoveryMethod2020.ts"],"names":[],"mappings":";;;AAGA,yCAAsH;AACtH,0FAA4F;AAE5F,MAAM,EAAE,MAAM,EAAE,GAAG,kBAAW,CAAA;AAEjB,QAAA,uCAAuC,GAAG,4DAA4D,CAAA;AAOnH;;GAEG;AACH,MAAa,mCAAoC,SAAQ,6BAAsB;IAG7E;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,YAAmB,OAAmD;QACpE,KAAK,CAAC;YACJ,IAAI,EAAE,qCAAqC;YAC3C,SAAS,EAAE,OAAO;YAClB,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,UAAU,EAAE,+CAAuC;YACnD,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;SAC7C,CAAC,CAAA;QACF,IAAI,CAAC,eAAe,GAAG,kCAAkC,CAAA;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EAAE,CAAC,CAAA;IACpG,CAAC;;AAhGH,kFAiGC;AAhGe,+CAAW,GAAG,+CAAuC,CAAA;AAkGrE,SAAS,0BAA0B,CAAC,OAAgC;IAClE,oEAAoE;IACpE,MAAM,YAAY,GAAG,IAAA,6BAAgB,EAAC;QACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,UAAU,EAAE,+CAAuC;KACpD,CAAC,CAAA;IACF,MAAM,OAAO,GAAG,IAAA,6BAAgB,EAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,UAAU,EAAE,iCAA0B,EAAE,CAAC,CAAA;IACxG,MAAM,QAAQ,GAAG,IAAA,6BAAgB,EAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,UAAU,EAAE,2BAAoB,EAAE,CAAC,CAAA;IAEnG,IAAI,YAAY,IAAI,OAAO,EAAE;QAC3B,sEAAsE;QACtE,iGAAiG;QACjG,OAAO,KAAK,CAAA;KACb;IAED,IAAI,YAAY,IAAI,QAAQ,EAAE;QAC5B,mEAAmE;QACnE,gGAAgG;QAChG,OAAO,KAAK,CAAA;KACb;IAED,+CAA+C;IAC/C,OAAO,YAAY,IAAI,OAAO,IAAI,QAAQ,CAAA;AAC5C,CAAC;AAED,SAAS,mBAAmB,CAAC,kBAA6B;IACxD,6DAA6D;IAC7D,uDAAuD;IACvD,OAAO,MAAM,CAAC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,EAAE,kCAAkC,CAAC,CAAA;AACxF,CAAC;AAED,SAAS,6BAA6B,CAAC,QAAmB;IACxD,OAAO,IAAA,6BAAgB,EAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,+CAAuC,EAAE,CAAC,CAAA;AAC5F,CAAC"}
@@ -0,0 +1,60 @@
1
+ import type { DocumentLoader, JwsLinkedDataSignatureOptions, Proof } from '@credo-ts/core';
2
+ import type { JsonLdDoc } from '@credo-ts/core/build/modules/vc/data-integrity/jsonldUtil';
3
+ import { JwsLinkedDataSignature } from '@credo-ts/core';
4
+ export declare const SECURITY_CONTEXT_SECP256k1_URL = "https://w3id.org/security/suites/secp256k1-2019/v1";
5
+ type EcdsaSecp256k1Signature2019Options = Pick<JwsLinkedDataSignatureOptions, 'key' | 'proof' | 'date' | 'useNativeCanonize' | 'LDKeyClass'>;
6
+ /**
7
+ * A secp256k1 signature suite for use with k251 key pairs
8
+ */
9
+ export declare class EcdsaSecp256k1Signature2019 extends JwsLinkedDataSignature {
10
+ static CONTEXT_URL: string;
11
+ /**
12
+ * @param {object} options - Options hashmap.
13
+ *
14
+ * Either a `key` OR at least one of `signer`/`verifier` is required.
15
+ *
16
+ * @param {object} [options.key] - An optional key object (containing an
17
+ * `id` property, and either `signer` or `verifier`, depending on the
18
+ * intended operation. Useful for when the application is managing keys
19
+ * itself (when using a KMS, you never have access to the private key,
20
+ * and so should use the `signer` param instead).
21
+ * @param {Function} [options.signer] - Signer function that returns an
22
+ * object with an async sign() method. This is useful when interfacing
23
+ * with a KMS (since you don't get access to the private key and its
24
+ * `signer()`, the KMS client gives you only the signer function to use).
25
+ * @param {Function} [options.verifier] - Verifier function that returns
26
+ * an object with an async `verify()` method. Useful when working with a
27
+ * KMS-provided verifier function.
28
+ *
29
+ * Advanced optional parameters and overrides.
30
+ *
31
+ * @param {object} [options.proof] - A JSON-LD document with options to use
32
+ * for the `proof` node. Any other custom fields can be provided here
33
+ * using a context different from security-v2).
34
+ * @param {string|Date} [options.date] - Signing date to use if not passed.
35
+ * @param {boolean} [options.useNativeCanonize] - Whether to use a native
36
+ * canonize algorithm.
37
+ */
38
+ constructor(options: EcdsaSecp256k1Signature2019Options);
39
+ assertVerificationMethod(document: JsonLdDoc): Promise<void>;
40
+ getVerificationMethod(options: {
41
+ proof: Proof;
42
+ documentLoader?: DocumentLoader;
43
+ }): Promise<any>;
44
+ /**
45
+ * Ensures the document to be signed contains the required signature suite
46
+ * specific `@context`, by either adding it (if `addSuiteContext` is true),
47
+ * or throwing an error if it's missing.
48
+ *
49
+ * @override
50
+ *
51
+ * @param {object} options - Options hashmap.
52
+ * @param {object} options.document - JSON-LD document to be signed.
53
+ * @param {boolean} options.addSuiteContext - Add suite context?
54
+ */
55
+ ensureSuiteContext(options: {
56
+ document: JsonLdDoc;
57
+ addSuiteContext: boolean;
58
+ }): void;
59
+ }
60
+ export {};
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EcdsaSecp256k1Signature2019 = exports.SECURITY_CONTEXT_SECP256k1_URL = void 0;
4
+ const core_1 = require("@credo-ts/core");
5
+ const jsonldUtil_1 = require("@credo-ts/core/build/modules/vc/data-integrity/jsonldUtil");
6
+ const { jsonld } = core_1.vcLibraries;
7
+ exports.SECURITY_CONTEXT_SECP256k1_URL = 'https://w3id.org/security/suites/secp256k1-2019/v1';
8
+ /**
9
+ * A secp256k1 signature suite for use with k251 key pairs
10
+ */
11
+ class EcdsaSecp256k1Signature2019 extends core_1.JwsLinkedDataSignature {
12
+ /**
13
+ * @param {object} options - Options hashmap.
14
+ *
15
+ * Either a `key` OR at least one of `signer`/`verifier` is required.
16
+ *
17
+ * @param {object} [options.key] - An optional key object (containing an
18
+ * `id` property, and either `signer` or `verifier`, depending on the
19
+ * intended operation. Useful for when the application is managing keys
20
+ * itself (when using a KMS, you never have access to the private key,
21
+ * and so should use the `signer` param instead).
22
+ * @param {Function} [options.signer] - Signer function that returns an
23
+ * object with an async sign() method. This is useful when interfacing
24
+ * with a KMS (since you don't get access to the private key and its
25
+ * `signer()`, the KMS client gives you only the signer function to use).
26
+ * @param {Function} [options.verifier] - Verifier function that returns
27
+ * an object with an async `verify()` method. Useful when working with a
28
+ * KMS-provided verifier function.
29
+ *
30
+ * Advanced optional parameters and overrides.
31
+ *
32
+ * @param {object} [options.proof] - A JSON-LD document with options to use
33
+ * for the `proof` node. Any other custom fields can be provided here
34
+ * using a context different from security-v2).
35
+ * @param {string|Date} [options.date] - Signing date to use if not passed.
36
+ * @param {boolean} [options.useNativeCanonize] - Whether to use a native
37
+ * canonize algorithm.
38
+ */
39
+ constructor(options) {
40
+ super({
41
+ type: 'EcdsaSecp256k1Signature2019',
42
+ algorithm: 'EcDSA',
43
+ LDKeyClass: options.LDKeyClass,
44
+ contextUrl: exports.SECURITY_CONTEXT_SECP256k1_URL,
45
+ key: options.key,
46
+ proof: options.proof,
47
+ date: options.date,
48
+ useNativeCanonize: options.useNativeCanonize,
49
+ });
50
+ this.requiredKeyType = 'EcdsaSecp256k1VerificationKey2019';
51
+ }
52
+ async assertVerificationMethod(document) {
53
+ if (!_includesCompatibleContext({ document: document })) {
54
+ // For DID Documents, since keys do not have their own contexts,
55
+ // the suite context is usually provided by the documentLoader logic
56
+ throw new TypeError(`The '@context' of the verification method (key) MUST contain the context url "${this.contextUrl}".`);
57
+ }
58
+ if (!_isSecp256k12019Key(document)) {
59
+ const verificationMethodType = jsonld.getValues(document, 'type')[0];
60
+ throw new Error(`Unsupported verification method type '${verificationMethodType}'. Verification method type MUST be 'EcdsaSecp256k1VerificationKey2019'.`);
61
+ }
62
+ else if (_isSecp256k12019Key(document) && !_includesSecp256k12019Context(document)) {
63
+ throw new Error(`For verification method type 'EcdsaSecp256k1VerificationKey2019' the '@context' MUST contain the context url "${exports.SECURITY_CONTEXT_SECP256k1_URL}".`);
64
+ }
65
+ // ensure verification method has not been revoked
66
+ if (document.revoked !== undefined) {
67
+ throw new Error('The verification method has been revoked.');
68
+ }
69
+ }
70
+ async getVerificationMethod(options) {
71
+ const verificationMethod = await super.getVerificationMethod({
72
+ proof: options.proof,
73
+ documentLoader: options.documentLoader,
74
+ });
75
+ return verificationMethod;
76
+ }
77
+ /**
78
+ * Ensures the document to be signed contains the required signature suite
79
+ * specific `@context`, by either adding it (if `addSuiteContext` is true),
80
+ * or throwing an error if it's missing.
81
+ *
82
+ * @override
83
+ *
84
+ * @param {object} options - Options hashmap.
85
+ * @param {object} options.document - JSON-LD document to be signed.
86
+ * @param {boolean} options.addSuiteContext - Add suite context?
87
+ */
88
+ ensureSuiteContext(options) {
89
+ if (_includesCompatibleContext({ document: options.document })) {
90
+ return;
91
+ }
92
+ super.ensureSuiteContext({ document: options.document, addSuiteContext: options.addSuiteContext });
93
+ }
94
+ }
95
+ exports.EcdsaSecp256k1Signature2019 = EcdsaSecp256k1Signature2019;
96
+ EcdsaSecp256k1Signature2019.CONTEXT_URL = exports.SECURITY_CONTEXT_SECP256k1_URL;
97
+ function _includesCompatibleContext(options) {
98
+ // Handle the EcdsaSecp256k1Signature2019 / credentials/v1 collision
99
+ const hasSecp256k1 = (0, jsonldUtil_1._includesContext)({
100
+ document: options.document,
101
+ contextUrl: exports.SECURITY_CONTEXT_SECP256k1_URL,
102
+ });
103
+ const hasCred = (0, jsonldUtil_1._includesContext)({ document: options.document, contextUrl: core_1.CREDENTIALS_CONTEXT_V1_URL });
104
+ const hasSecV2 = (0, jsonldUtil_1._includesContext)({ document: options.document, contextUrl: core_1.SECURITY_CONTEXT_URL });
105
+ if (hasSecp256k1 && hasCred) {
106
+ // The secp256k1-2019/v1 and credentials/v1 contexts are incompatible.
107
+ // For VCs using EcdsaSecp256k1Signature2019 suite using the credentials/v1 context is sufficient
108
+ return false;
109
+ }
110
+ if (hasSecp256k1 && hasSecV2) {
111
+ // The secp256k1-2019/v1 and security/v2 contexts are incompatible.
112
+ // For VCs using EcdsaSecp256k1Signature2019 suite, using the security/v2 context is sufficient.
113
+ return false;
114
+ }
115
+ // Either one by itself is fine, for this suite
116
+ return hasSecp256k1 || hasCred || hasSecV2;
117
+ }
118
+ function _isSecp256k12019Key(verificationMethod) {
119
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
120
+ // @ts-ignore - .hasValue is not part of the public API
121
+ return jsonld.hasValue(verificationMethod, 'type', 'EcdsaSecp256k1VerificationKey2019');
122
+ }
123
+ function _includesSecp256k12019Context(document) {
124
+ return (0, jsonldUtil_1._includesContext)({ document, contextUrl: exports.SECURITY_CONTEXT_SECP256k1_URL });
125
+ }
126
+ //# sourceMappingURL=EcdsaSecp256k1Signature2019.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EcdsaSecp256k1Signature2019.js","sourceRoot":"","sources":["../../src/signature-suites/EcdsaSecp256k1Signature2019.ts"],"names":[],"mappings":";;;AAGA,yCAAsH;AACtH,0FAA4F;AAE5F,MAAM,EAAE,MAAM,EAAE,GAAG,kBAAW,CAAA;AAEjB,QAAA,8BAA8B,GAAG,oDAAoD,CAAA;AAOlG;;GAEG;AACH,MAAa,2BAA4B,SAAQ,6BAAsB;IAGrE;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,YAAmB,OAA2C;QAC5D,KAAK,CAAC;YACJ,IAAI,EAAE,6BAA6B;YACnC,SAAS,EAAE,OAAO;YAClB,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,UAAU,EAAE,sCAA8B;YAC1C,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;SAC7C,CAAC,CAAA;QACF,IAAI,CAAC,eAAe,GAAG,mCAAmC,CAAA;IAC5D,CAAC;IAEM,KAAK,CAAC,wBAAwB,CAAC,QAAmB;QACvD,IAAI,CAAC,0BAA0B,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,EAAE;YACvD,gEAAgE;YAChE,oEAAoE;YACpE,MAAM,IAAI,SAAS,CACjB,iFAAiF,IAAI,CAAC,UAAU,IAAI,CACrG,CAAA;SACF;QAED,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE;YAClC,MAAM,sBAAsB,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;YACpE,MAAM,IAAI,KAAK,CACb,yCAAyC,sBAAsB,0EAA0E,CAC1I,CAAA;SACF;aAAM,IAAI,mB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