@interop/ecdsa-multikey 2.0.0

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 (44) hide show
  1. package/CHANGELOG.md +146 -0
  2. package/LICENSE +29 -0
  3. package/README.md +163 -0
  4. package/dist/baseX.d.ts +7 -0
  5. package/dist/baseX.d.ts.map +1 -0
  6. package/dist/baseX.js +11 -0
  7. package/dist/baseX.js.map +1 -0
  8. package/dist/constants.d.ts +29 -0
  9. package/dist/constants.d.ts.map +1 -0
  10. package/dist/constants.js +43 -0
  11. package/dist/constants.js.map +1 -0
  12. package/dist/crypto-browser.d.ts +9 -0
  13. package/dist/crypto-browser.d.ts.map +1 -0
  14. package/dist/crypto-browser.js +7 -0
  15. package/dist/crypto-browser.js.map +1 -0
  16. package/dist/crypto.d.ts +7 -0
  17. package/dist/crypto.d.ts.map +1 -0
  18. package/dist/crypto.js +12 -0
  19. package/dist/crypto.js.map +1 -0
  20. package/dist/factory.d.ts +10 -0
  21. package/dist/factory.d.ts.map +1 -0
  22. package/dist/factory.js +55 -0
  23. package/dist/factory.js.map +1 -0
  24. package/dist/helpers.d.ts +18 -0
  25. package/dist/helpers.d.ts.map +1 -0
  26. package/dist/helpers.js +82 -0
  27. package/dist/helpers.js.map +1 -0
  28. package/dist/index.d.ts +29 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +221 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/serialize.d.ts +44 -0
  33. package/dist/serialize.d.ts.map +1 -0
  34. package/dist/serialize.js +302 -0
  35. package/dist/serialize.js.map +1 -0
  36. package/dist/translators.d.ts +5 -0
  37. package/dist/translators.d.ts.map +1 -0
  38. package/dist/translators.js +40 -0
  39. package/dist/translators.js.map +1 -0
  40. package/dist/types.d.ts +69 -0
  41. package/dist/types.d.ts.map +1 -0
  42. package/dist/types.js +5 -0
  43. package/dist/types.js.map +1 -0
  44. package/package.json +72 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,146 @@
1
+ # @interop/ecdsa-multikey ChangeLog
2
+
3
+ ## 2.0.0 - 2026-06-07
4
+
5
+ ### Changed
6
+
7
+ - **BREAKING**: Forked from
8
+ [`@digitalbazaar/ecdsa-multikey@1.8.0`](https://github.com/digitalbazaar/ecdsa-multikey)
9
+ and published as `@interop/ecdsa-multikey`. No library behavior or public API
10
+ changes.
11
+
12
+ ### Added
13
+
14
+ - Test-only: added known-answer JWK vectors for the existing mock keys
15
+ (asserting exact `toJwk()` encodings and `fromJwk()` round-trips), imported
16
+ the Project Wycheproof IEEE P1363 ECDSA verification vectors for
17
+ P-256/P-384/P-521 to exercise the verifier against externally-produced and
18
+ malformed signatures, and added negative-path tests covering the library's
19
+ error branches (invalid curve/multibase/JWK inputs, curve mismatches,
20
+ unsupported key types and contexts) plus positive-path branch tests for
21
+ optional inputs (`controller`-derived `id`, `fromJwk` `id`/`controller`,
22
+ `includeContext`/secret-only export, array `@context`). No library behavior or
23
+ public API changes.
24
+
25
+ ### Changed
26
+
27
+ - Replaced the `base58-universal` and `base64url-universal` dependencies with
28
+ `@scure/base` (via a small `src/baseX.ts` wrapper). No library behavior or
29
+ public API changes.
30
+ - **Infrastructure only; no library behavior, public API, or return-shape
31
+ changes.** Migrated the build/test toolchain to the `isomorphic-lib-template`:
32
+ pnpm (replacing npm), Vite/Vitest for Node tests (replacing Mocha/Chai/c8),
33
+ Playwright for the browser smoke test (replacing Karma/webpack), ESLint flat
34
+ config + Prettier 3 (replacing `eslint-config-digitalbazaar`), and a
35
+ single-entry `tsc` build to `dist/`.
36
+ - Converted the source from JavaScript (`lib/*.js`) to TypeScript (`src/*.ts`).
37
+ The package now ships compiled output and type declarations from `dist/`, with
38
+ conditional `exports`. The `node:crypto` vs `globalThis.crypto` browser swap
39
+ is preserved via the `browser` field.
40
+ - Raised the minimum Node.js version to `>= 24`.
41
+ - The TypeScript build runs under full `strict` mode, including
42
+ `verbatimModuleSyntax` and `noUncheckedIndexedAccess`.
43
+
44
+ ## 1.8.0 - 2024-10-02
45
+
46
+ ### Added
47
+
48
+ - Include `id` and `controller` properties when importing key types of
49
+ `JsonWebKey` or `JsonWebKey2020`.
50
+
51
+ ## 1.7.0 - 2024-03-17
52
+
53
+ ### Added
54
+
55
+ - Add conversion from `publicKeyJwk` feature via `from()`.
56
+
57
+ ### Changed
58
+
59
+ - Expect >= node 18 via `package.json`.
60
+
61
+ ### Fixed
62
+
63
+ - Allow `@context` array values in multikeys.
64
+
65
+ ## 1.6.0 - 2023-11-07
66
+
67
+ ### Added
68
+
69
+ - Add `fromRaw()` to import a key pair from a named `curve`, `secretKey`, and
70
+ `publicKey`.
71
+ - Reformat `keyAgreement` param in `from()` to `options` to enable named usage
72
+ (`{keyAgreement: true|false}`) for better API.
73
+
74
+ ## 1.5.0 - 2023-11-05
75
+
76
+ ### Added
77
+
78
+ - Rename `remotePublicKey` param to `publicKey` for `deriveSecret()` to get
79
+ better compatibility with WebKMS Client KeyAgreementKey interface. The param
80
+ can still be passed as `remotePublicKey` but this is considered deprecated.
81
+
82
+ ## 1.4.0 - 2023-11-05
83
+
84
+ ### Added
85
+
86
+ - Add `raw` option to key pair `export()`. Based on the requested public/secret
87
+ key, the output will include the raw bytes for the public/secret key using the
88
+ properties `publicKey` and/or `secretKey`, respectively. The public key will
89
+ be output using the compressed format.
90
+
91
+ ## 1.3.0 - 2023-10-31
92
+
93
+ ### Added
94
+
95
+ - Add `keyAgreement` option to `generate()` to generate ECDH keys instead of
96
+ ECDSA keys. This module needs a better name than `ecdsa-multikey` as it also
97
+ supports key agreement keys, but only for keys based on curves that are also
98
+ compatible with ECDSA. Note that a key should only be used for ECDSA or ECDH
99
+ (key agreement), not both, so calling this module `ecdsa-multikey` is a bit
100
+ misleading as you can also generate a key that is to only be used for key
101
+ agreement.
102
+ - Add `deriveSecret()` API for `keyAgreement` enabled keys.
103
+
104
+ ## 1.2.1 - 2023-10-30
105
+
106
+ ### Fixed
107
+
108
+ - Do not include `ext` or `key_ops` in output JWK.
109
+
110
+ ## 1.2.0 - 2023-10-30
111
+
112
+ ### Added
113
+
114
+ - Add `fromJwk()` and `toJwk()` for importing / exporting key pairs using JWK.
115
+
116
+ ## 1.1.3 - 2023-05-19
117
+
118
+ ### Fixed
119
+
120
+ - Support Node.js 20.x.
121
+
122
+ ## 1.1.2 - 2023-04-14
123
+
124
+ ### Fixed
125
+
126
+ - Update `.from()` method to not modify key input.
127
+
128
+ ## 1.1.1 - 2023-03-11
129
+
130
+ ### Fixed
131
+
132
+ - Fix data format alignment issues with ecdsa-2019-cryptosuite.
133
+ - Use constant strings in tests.
134
+
135
+ ## 1.1.0 - 2023-03-06
136
+
137
+ ### Changed
138
+
139
+ - Ensure public and secret multikey headers match.
140
+ - Change exported algorithm from "ECDSA" to curve name.
141
+
142
+ ## 1.0.0 - 2023-02-27
143
+
144
+ ### Added
145
+
146
+ - Initial version.
package/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, Digital Bazaar, Inc.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # EcdsaMultikey Key Pair Library for Linked Data _(@interop/ecdsa-multikey)_
2
+
3
+ [![CI](https://github.com/interop-alliance/ecdsa-multikey/actions/workflows/ci.yml/badge.svg)](https://github.com/interop-alliance/ecdsa-multikey/actions/workflows/ci.yml)
4
+ [![NPM Version](https://img.shields.io/npm/v/@interop/ecdsa-multikey.svg)](https://npm.im/@interop/ecdsa-multikey)
5
+
6
+ > TypeScript/JavaScript library for generating and working with EcdsaMultikey
7
+ > key pairs.
8
+
9
+ ## Table of Contents
10
+
11
+ - [Background](#background)
12
+ - [Security](#security)
13
+ - [Install](#install)
14
+ - [Usage](#usage)
15
+ - [Contribute](#contribute)
16
+ - [Commercial Support](#commercial-support)
17
+ - [License](#license)
18
+
19
+ ## Background
20
+
21
+ (Forked from
22
+ [`digitalbazaar/ecdsa-multikey`](https://github.com/digitalbazaar/ecdsa-multikey)
23
+ to provide TypeScript compatibility.)
24
+
25
+ For use with:
26
+
27
+ - [`@digitalbazaar/ecdsa-2019-cryptosuite`](https://github.com/digitalbazaar/ecdsa-2019-cryptosuite)
28
+ `^1.0.0` crypto suite (with
29
+ [`jsonld-signatures`](https://github.com/digitalbazaar/jsonld-signatures)
30
+ `^11.0.0`)
31
+ - [`@digitalbazaar/data-integrity`](https://github.com/digitalbazaar/data-integrity)
32
+ `^1.0.0`
33
+
34
+ See also (related specs):
35
+
36
+ - [Verifiable Credential Data Integrity](https://w3c.github.io/vc-data-integrity/)
37
+
38
+ ## Security
39
+
40
+ As with most security- and cryptography-related tools, the overall security of
41
+ your system will largely depend on your design decisions.
42
+
43
+ ## Install
44
+
45
+ - Node.js 24+ is required.
46
+ - This package is built with [pnpm](https://pnpm.io/).
47
+
48
+ To install as a dependency:
49
+
50
+ ```
51
+ npm install @interop/ecdsa-multikey
52
+ ```
53
+
54
+ To install locally (for development):
55
+
56
+ ```
57
+ git clone https://github.com/interop-alliance/ecdsa-multikey.git
58
+ cd ecdsa-multikey
59
+ pnpm install
60
+ ```
61
+
62
+ ## Usage
63
+
64
+ ### Generating a new public/secret key pair
65
+
66
+ To generate a new public/secret key pair:
67
+
68
+ - `{string} [curve]` \[Required\] ECDSA curve used to generate the key:
69
+ \['P-256', 'P-384', 'P-521'\].
70
+ - `{string} [id]` \[Optional\] ID for the generated key.
71
+ - `{string} [controller]` \[Optional\] Controller URI or DID to initialize the
72
+ generated key. (This will be used to generate `id` if it is not explicitly
73
+ defined.)
74
+
75
+ ```js
76
+ import * as EcdsaMultikey from '@interop/ecdsa-multikey'
77
+
78
+ const keyPair = await EcdsaMultikey.generate({ curve: 'P-384' })
79
+ ```
80
+
81
+ ### Importing a key pair from storage
82
+
83
+ To create an instance of a public/secret key pair from data imported from
84
+ storage, use `.from()`:
85
+
86
+ ```js
87
+ const serializedKeyPair = { ... };
88
+
89
+ const keyPair = await EcdsaMultikey.from(serializedKeyPair);
90
+ ```
91
+
92
+ ### Exporting the public key only
93
+
94
+ To export just the public key of a pair:
95
+
96
+ ```js
97
+ await keyPair.export({publicKey: true});
98
+ // ->
99
+ {
100
+ type: 'Multikey',
101
+ id: 'did:example:1234#zDnaeSMnptAKpH4AD41vTkwzjznW7yNetdRh9FJn8bJsbsdbw',
102
+ controller: 'did:example:1234',
103
+ publicKeyMultibase: 'zDnaeSMnptAKpH4AD41vTkwzjznW7yNetdRh9FJn8bJsbsdbw'
104
+ }
105
+ ```
106
+
107
+ ### Exporting the full public-secret key pair
108
+
109
+ To export the full key pair, including secret key (warning: this should be a
110
+ carefully considered operation, best left to dedicated Key Management Systems):
111
+
112
+ ```js
113
+ await keyPair.export({publicKey: true, secretKey: true});
114
+ // ->
115
+ {
116
+ type: 'Multikey',
117
+ id: 'did:example:1234#zDnaeSMnptAKpH4AD41vTkwzjznW7yNetdRh9FJn8bJsbsdbw',
118
+ controller: 'did:example:1234',
119
+ publicKeyMultibase: 'zDnaeSMnptAKpH4AD41vTkwzjznW7yNetdRh9FJn8bJsbsdbw',
120
+ secretKeyMultibase: 'z42twirSb1PULt5Sg6gjgNMsdiLycu6fbA83aX1vVb8e3ncP'
121
+ }
122
+ ```
123
+
124
+ ### Creating a signer function
125
+
126
+ In order to perform a cryptographic signature, you need to create a `sign`
127
+ function, and then invoke it.
128
+
129
+ ```js
130
+ const keyPair = EcdsaMultikey.generate({ curve: 'P-256' })
131
+
132
+ const { sign } = keyPair.signer()
133
+
134
+ // data is a Uint8Array of bytes
135
+ const data = new TextEncoder().encode('test data goes here')
136
+ // Signing also outputs a Uint8Array, which you can serialize to text etc.
137
+ const signature = await sign({ data })
138
+ ```
139
+
140
+ ### Creating a verifier function
141
+
142
+ In order to verify a cryptographic signature, you need to create a `verify`
143
+ function, and then invoke it (passing it the data to verify, and the signature).
144
+
145
+ ```js
146
+ const keyPair = EcdsaMultikey.generate({ curve: 'P-521' })
147
+
148
+ const { verify } = keyPair.verifier()
149
+
150
+ const valid = await verify({ data, signature })
151
+ // true
152
+ ```
153
+
154
+ ## Contribute
155
+
156
+ PRs accepted.
157
+
158
+ If editing the Readme, please conform to the
159
+ [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
160
+
161
+ ## License
162
+
163
+ [New BSD License (3-clause)](LICENSE) © 2023 Digital Bazaar
@@ -0,0 +1,7 @@
1
+ export declare const base58btc: import("@scure/base").BytesCoder;
2
+ /**
3
+ * base64url must be RFC 4648 compliant for JWK interop, and JWK uses the
4
+ * unpadded form, hence `base64urlnopad`.
5
+ */
6
+ export declare const base64url: import("@scure/base").BytesCoder;
7
+ //# sourceMappingURL=baseX.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseX.d.ts","sourceRoot":"","sources":["../src/baseX.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,kCAAS,CAAA;AAE/B;;;GAGG;AACH,eAAO,MAAM,SAAS,kCAAiB,CAAA"}
package/dist/baseX.js ADDED
@@ -0,0 +1,11 @@
1
+ /*!
2
+ * Copyright (c) 2019-2026 Digital Bazaar, Inc.
3
+ */
4
+ import { base58, base64urlnopad } from '@scure/base';
5
+ export const base58btc = base58;
6
+ /**
7
+ * base64url must be RFC 4648 compliant for JWK interop, and JWK uses the
8
+ * unpadded form, hence `base64urlnopad`.
9
+ */
10
+ export const base64url = base64urlnopad;
11
+ //# sourceMappingURL=baseX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseX.js","sourceRoot":"","sources":["../src/baseX.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEpD,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAA;AAE/B;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,cAAc,CAAA"}
@@ -0,0 +1,29 @@
1
+ /*!
2
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ export declare const ALGORITHM = "ECDSA";
5
+ export declare const EXTRACTABLE = true;
6
+ export declare const ECDSA_2019_SECP_256_KEY_TYPE = "EcdsaSecp256r1VerificationKey2019";
7
+ export declare const ECDSA_2019_SECP_384_KEY_TYPE = "EcdsaSecp384r1VerificationKey2019";
8
+ export declare const ECDSA_2019_SECP_521_KEY_TYPE = "EcdsaSecp521r1VerificationKey2019";
9
+ export declare const ECDSA_2019_SUITE_CONTEXT_V1_URL = "https://w3id.org/security/suites/ecdsa-2019/v1";
10
+ export declare const MULTIKEY_CONTEXT_V1_URL = "https://w3id.org/security/multikey/v1";
11
+ export declare const MULTIBASE_BASE58_HEADER = "z";
12
+ export declare const MULTICODEC_P256_PUBLIC_KEY_HEADER: Uint8Array<ArrayBuffer>;
13
+ export declare const MULTICODEC_P384_PUBLIC_KEY_HEADER: Uint8Array<ArrayBuffer>;
14
+ export declare const MULTICODEC_P521_PUBLIC_KEY_HEADER: Uint8Array<ArrayBuffer>;
15
+ export declare const MULTICODEC_P256_SECRET_KEY_HEADER: Uint8Array<ArrayBuffer>;
16
+ export declare const MULTICODEC_P384_SECRET_KEY_HEADER: Uint8Array<ArrayBuffer>;
17
+ export declare const MULTICODEC_P521_SECRET_KEY_HEADER: Uint8Array<ArrayBuffer>;
18
+ export declare const ECDSA_CURVE: {
19
+ readonly P256: "P-256";
20
+ readonly P384: "P-384";
21
+ readonly P521: "P-521";
22
+ };
23
+ export declare const ECDSA_HASH: {
24
+ readonly SHA256: "SHA-256";
25
+ readonly SHA384: "SHA-384";
26
+ readonly SHA512: "SHA-512";
27
+ };
28
+ export type EcdsaCurve = (typeof ECDSA_CURVE)[keyof typeof ECDSA_CURVE];
29
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,SAAS,UAAU,CAAA;AAEhC,eAAO,MAAM,WAAW,OAAO,CAAA;AAE/B,eAAO,MAAM,4BAA4B,sCAAsC,CAAA;AAE/E,eAAO,MAAM,4BAA4B,sCAAsC,CAAA;AAE/E,eAAO,MAAM,4BAA4B,sCAAsC,CAAA;AAE/E,eAAO,MAAM,+BAA+B,mDACM,CAAA;AAElD,eAAO,MAAM,uBAAuB,0CAA0C,CAAA;AAC9E,eAAO,MAAM,uBAAuB,MAAM,CAAA;AAG1C,eAAO,MAAM,iCAAiC,yBAA+B,CAAA;AAE7E,eAAO,MAAM,iCAAiC,yBAA+B,CAAA;AAE7E,eAAO,MAAM,iCAAiC,yBAA+B,CAAA;AAG7E,eAAO,MAAM,iCAAiC,yBAA+B,CAAA;AAE7E,eAAO,MAAM,iCAAiC,yBAA+B,CAAA;AAE7E,eAAO,MAAM,iCAAiC,yBAA+B,CAAA;AAG7E,eAAO,MAAM,WAAW;;;;CAId,CAAA;AAGV,eAAO,MAAM,UAAU;;;;CAIb,CAAA;AAGV,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAA"}
@@ -0,0 +1,43 @@
1
+ /*!
2
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ // Name of algorithm
5
+ export const ALGORITHM = 'ECDSA';
6
+ // Determines whether key pair is extractable
7
+ export const EXTRACTABLE = true;
8
+ // ECDSA curve P-256 type
9
+ export const ECDSA_2019_SECP_256_KEY_TYPE = 'EcdsaSecp256r1VerificationKey2019';
10
+ // ECDSA curve P-384 type
11
+ export const ECDSA_2019_SECP_384_KEY_TYPE = 'EcdsaSecp384r1VerificationKey2019';
12
+ // ECDSA curve P-521 type
13
+ export const ECDSA_2019_SECP_521_KEY_TYPE = 'EcdsaSecp521r1VerificationKey2019';
14
+ // ECDSA 2019 suite context v1 URL
15
+ export const ECDSA_2019_SUITE_CONTEXT_V1_URL = 'https://w3id.org/security/suites/ecdsa-2019/v1';
16
+ // Multikey context v1 URL
17
+ export const MULTIKEY_CONTEXT_V1_URL = 'https://w3id.org/security/multikey/v1';
18
+ export const MULTIBASE_BASE58_HEADER = 'z';
19
+ // Multicodec p256-pub header (0x1200 varint -> 0x8024 hex)
20
+ export const MULTICODEC_P256_PUBLIC_KEY_HEADER = new Uint8Array([0x80, 0x24]);
21
+ // Multicodec p384-pub header (0x1201 varint -> 0x8124 hex)
22
+ export const MULTICODEC_P384_PUBLIC_KEY_HEADER = new Uint8Array([0x81, 0x24]);
23
+ // Multicodec p521-pub header (0x1202 varint -> 0x8224 hex)
24
+ export const MULTICODEC_P521_PUBLIC_KEY_HEADER = new Uint8Array([0x82, 0x24]);
25
+ // Multicodec p256-priv header (0x1306 varint -> 0x8626 hex)
26
+ export const MULTICODEC_P256_SECRET_KEY_HEADER = new Uint8Array([0x86, 0x26]);
27
+ // Multicodec p384-priv header (0x1307 varint -> 0x8726 hex)
28
+ export const MULTICODEC_P384_SECRET_KEY_HEADER = new Uint8Array([0x87, 0x26]);
29
+ // Multicodec p521-priv header (0x1308 varint -> 0x8826 hex)
30
+ export const MULTICODEC_P521_SECRET_KEY_HEADER = new Uint8Array([0x88, 0x26]);
31
+ // ECDSA curves
32
+ export const ECDSA_CURVE = {
33
+ P256: 'P-256',
34
+ P384: 'P-384',
35
+ P521: 'P-521'
36
+ };
37
+ // ECDSA hash functions
38
+ export const ECDSA_HASH = {
39
+ SHA256: 'SHA-256',
40
+ SHA384: 'SHA-384',
41
+ SHA512: 'SHA-512'
42
+ };
43
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAoB;AACpB,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAAA;AAChC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAA;AAC/B,yBAAyB;AACzB,MAAM,CAAC,MAAM,4BAA4B,GAAG,mCAAmC,CAAA;AAC/E,yBAAyB;AACzB,MAAM,CAAC,MAAM,4BAA4B,GAAG,mCAAmC,CAAA;AAC/E,yBAAyB;AACzB,MAAM,CAAC,MAAM,4BAA4B,GAAG,mCAAmC,CAAA;AAC/E,kCAAkC;AAClC,MAAM,CAAC,MAAM,+BAA+B,GAC1C,gDAAgD,CAAA;AAClD,0BAA0B;AAC1B,MAAM,CAAC,MAAM,uBAAuB,GAAG,uCAAuC,CAAA;AAC9E,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAA;AAE1C,2DAA2D;AAC3D,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAC7E,2DAA2D;AAC3D,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAC7E,2DAA2D;AAC3D,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAE7E,4DAA4D;AAC5D,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAC7E,4DAA4D;AAC5D,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAC7E,4DAA4D;AAC5D,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAE7E,eAAe;AACf,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,OAAO;CACL,CAAA;AAEV,uBAAuB;AACvB,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;CACT,CAAA"}
@@ -0,0 +1,9 @@
1
+ /*!
2
+ * Copyright (c) 2019-2023 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ export declare const webcrypto: Crypto;
5
+ export declare const CryptoKey: {
6
+ new (): CryptoKey;
7
+ prototype: CryptoKey;
8
+ };
9
+ //# sourceMappingURL=crypto-browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-browser.d.ts","sourceRoot":"","sources":["../src/crypto-browser.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,SAAS,QAAoB,CAAA;AAC1C,eAAO,MAAM,SAAS;;;CAE0D,CAAA"}
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * Copyright (c) 2019-2023 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ export const webcrypto = globalThis.crypto;
5
+ export const CryptoKey = globalThis.CryptoKey ??
6
+ webcrypto.CryptoKey;
7
+ //# sourceMappingURL=crypto-browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-browser.js","sourceRoot":"","sources":["../src/crypto-browser.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAA;AAC1C,MAAM,CAAC,MAAM,SAAS,GACpB,UAAU,CAAC,SAAS;IACnB,SAAmE,CAAC,SAAS,CAAA"}
@@ -0,0 +1,7 @@
1
+ declare const webcrypto: Crypto;
2
+ declare const CryptoKey: {
3
+ new (): CryptoKey;
4
+ prototype: CryptoKey;
5
+ };
6
+ export { CryptoKey, webcrypto };
7
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,SAAS,EAA+B,MAAM,CAAA;AACpD,QAAA,MAAM,SAAS;;;CAGD,CAAA;AAEd,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAA"}
package/dist/crypto.js ADDED
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * Copyright (c) 2019-2023 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import { webcrypto as nodeWebcrypto } from 'node:crypto';
5
+ // Use the standard (DOM) WebCrypto types so the API surface is identical in
6
+ // Node.js and the browser; the runtime implementation comes from `node:crypto`.
7
+ const webcrypto = nodeWebcrypto;
8
+ const CryptoKey = globalThis.CryptoKey ??
9
+ nodeWebcrypto
10
+ .CryptoKey;
11
+ export { CryptoKey, webcrypto };
12
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,aAAa,CAAA;AAExD,4EAA4E;AAC5E,gFAAgF;AAChF,MAAM,SAAS,GAAG,aAAkC,CAAA;AACpD,MAAM,SAAS,GACb,UAAU,CAAC,SAAS;IACnB,aAAuE;SACrE,SAAS,CAAA;AAEd,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { Signer, Verifier, WebCryptoKey } from './types.js';
2
+ export declare function createSigner({ id, secretKey }: {
3
+ id?: string;
4
+ secretKey?: WebCryptoKey;
5
+ }): Signer;
6
+ export declare function createVerifier({ id, publicKey }: {
7
+ id?: string;
8
+ publicKey?: WebCryptoKey;
9
+ }): Verifier;
10
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAGhE,wBAAgB,YAAY,CAAC,EAC3B,EAAE,EACF,SAAS,EACV,EAAE;IACD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,SAAS,CAAC,EAAE,YAAY,CAAA;CACzB,GAAG,MAAM,CAkBT;AAGD,wBAAgB,cAAc,CAAC,EAC7B,EAAE,EACF,SAAS,EACV,EAAE;IACD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,SAAS,CAAC,EAAE,YAAY,CAAA;CACzB,GAAG,QAAQ,CA2BX"}
@@ -0,0 +1,55 @@
1
+ /*!
2
+ * Copyright (c) 2022-2023 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import { ALGORITHM, ECDSA_CURVE, ECDSA_HASH } from './constants.js';
5
+ import { webcrypto } from './crypto.js';
6
+ // exposes sign method
7
+ export function createSigner({ id, secretKey }) {
8
+ if (!secretKey) {
9
+ throw new Error('"secretKey" is required for signing.');
10
+ }
11
+ const { namedCurve: curve } = secretKey.algorithm;
12
+ const algorithm = {
13
+ name: ALGORITHM,
14
+ hash: { name: _getEcdsaHash({ curve }) }
15
+ };
16
+ return {
17
+ algorithm: curve,
18
+ id,
19
+ async sign({ data }) {
20
+ return new Uint8Array(await webcrypto.subtle.sign(algorithm, secretKey, data));
21
+ }
22
+ };
23
+ }
24
+ // exposes verify method
25
+ export function createVerifier({ id, publicKey }) {
26
+ if (!publicKey) {
27
+ throw new Error('"publicKey" is required for verifying.');
28
+ }
29
+ const { namedCurve: curve } = publicKey.algorithm;
30
+ const algorithm = {
31
+ name: ALGORITHM,
32
+ hash: { name: _getEcdsaHash({ curve }) }
33
+ };
34
+ return {
35
+ algorithm: curve,
36
+ id,
37
+ async verify({ data, signature }) {
38
+ return webcrypto.subtle.verify(algorithm, publicKey, signature, data);
39
+ }
40
+ };
41
+ }
42
+ // retrieves name of appropriate ECDSA hash function
43
+ function _getEcdsaHash({ curve }) {
44
+ if (curve === ECDSA_CURVE.P256) {
45
+ return ECDSA_HASH.SHA256;
46
+ }
47
+ if (curve === ECDSA_CURVE.P384) {
48
+ return ECDSA_HASH.SHA384;
49
+ }
50
+ if (curve === ECDSA_CURVE.P521) {
51
+ return ECDSA_HASH.SHA512;
52
+ }
53
+ throw new TypeError(`Unsupported curve "${curve}".`);
54
+ }
55
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,sBAAsB;AACtB,MAAM,UAAU,YAAY,CAAC,EAC3B,EAAE,EACF,SAAS,EAIV;IACC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;IACzD,CAAC;IACD,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,SAA2B,CAAA;IACnE,MAAM,SAAS,GAAG;QAChB,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,EAAE,IAAI,EAAE,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;KACzC,CAAA;IACD,OAAO;QACL,SAAS,EAAE,KAAK;QAChB,EAAE;QACF,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAwB;YACvC,OAAO,IAAI,UAAU,CACnB,MAAM,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,IAAoB,CAAC,CACxE,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAED,wBAAwB;AACxB,MAAM,UAAU,cAAc,CAAC,EAC7B,EAAE,EACF,SAAS,EAIV;IACC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAC3D,CAAC;IACD,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,SAA2B,CAAA;IACnE,MAAM,SAAS,GAAG;QAChB,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,EAAE,IAAI,EAAE,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;KACzC,CAAA;IACD,OAAO;QACL,SAAS,EAAE,KAAK;QAChB,EAAE;QACF,KAAK,CAAC,MAAM,CAAC,EACX,IAAI,EACJ,SAAS,EAIV;YACC,OAAO,SAAS,CAAC,MAAM,CAAC,MAAM,CAC5B,SAAS,EACT,SAAS,EACT,SAAyB,EACzB,IAAoB,CACrB,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAED,oDAAoD;AACpD,SAAS,aAAa,CAAC,EAAE,KAAK,EAAqB;IACjD,IAAI,KAAK,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC;QAC/B,OAAO,UAAU,CAAC,MAAM,CAAA;IAC1B,CAAC;IACD,IAAI,KAAK,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC;QAC/B,OAAO,UAAU,CAAC,MAAM,CAAA;IAC1B,CAAC;IACD,IAAI,KAAK,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC;QAC/B,OAAO,UAAU,CAAC,MAAM,CAAA;IAC1B,CAAC;IACD,MAAM,IAAI,SAAS,CAAC,sBAAsB,KAAK,IAAI,CAAC,CAAA;AACtD,CAAC"}
@@ -0,0 +1,18 @@
1
+ export declare function getNamedCurveFromPublicMultikey({ publicMultikey }: {
2
+ publicMultikey: Uint8Array;
3
+ }): string;
4
+ export declare function getNamedCurveFromSecretMultikey({ secretMultikey }: {
5
+ secretMultikey: Uint8Array;
6
+ }): string;
7
+ export declare function getSecretKeySize({ curve }: {
8
+ curve: string;
9
+ }): number;
10
+ export declare function setSecretKeyHeader({ curve, buffer }: {
11
+ curve: string;
12
+ buffer: Uint8Array;
13
+ }): void;
14
+ export declare function setPublicKeyHeader({ curve, buffer }: {
15
+ curve: string;
16
+ buffer: Uint8Array;
17
+ }): void;
18
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAcA,wBAAgB,+BAA+B,CAAC,EAC9C,cAAc,EACf,EAAE;IACD,cAAc,EAAE,UAAU,CAAA;CAC3B,GAAG,MAAM,CAqBT;AAGD,wBAAgB,+BAA+B,CAAC,EAC9C,cAAc,EACf,EAAE;IACD,cAAc,EAAE,UAAU,CAAA;CAC3B,GAAG,MAAM,CAqBT;AAGD,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAWrE;AAGD,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,MAAM,EACP,EAAE;IACD,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,UAAU,CAAA;CACnB,GAAG,IAAI,CAUP;AAGD,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,MAAM,EACP,EAAE;IACD,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,UAAU,CAAA;CACnB,GAAG,IAAI,CAUP"}