@interop/x25519-key-agreement-key 4.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.
package/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2021, 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,144 @@
1
+ # X25519KeyAgreementKey2020 _(@interop/x25519-key-agreement-key)_
2
+
3
+ [![CI](https://github.com/interop-alliance/x25519-key-agreement-key/workflows/CI/badge.svg)](https://github.com/interop-alliance/x25519-key-agreement-key/actions?query=workflow%3ACI)
4
+ [![NPM Version](https://img.shields.io/npm/v/@interop/x25519-key-agreement-key)](https://www.npmjs.com/package/@interop/x25519-key-agreement-key)
5
+
6
+ > An X25519 (Curve25519) DH (Diffie-Hellman) key implementation to work with the
7
+ > X25519 2020 Crypto suite.
8
+
9
+ ## Table of Contents
10
+
11
+ - [Security](#security)
12
+ - [Background](#background)
13
+ - [Install](#install)
14
+ - [Usage](#usage)
15
+ - [Contribute](#contribute)
16
+ - [Commercial Support](#commercial-support)
17
+ - [License](#license)
18
+
19
+ ## Security
20
+
21
+ TBD
22
+
23
+ ## Background
24
+
25
+ (Forked from
26
+ [`digitalcredentials/x25519-key-agreement-key-2020`](https://github.com/digitalcredentials/x25519-key-agreement-key-2020),
27
+ which was in turn forked from
28
+ [`digitalbazaar/x25519-key-agreement-key-2020` v2.0.0](https://github.com/digitalbazaar/x25519-key-agreement-key-2020)
29
+ to provide TypeScript compatibility.)
30
+
31
+ For use with
32
+ [`@interop/data-integrity-core`](https://www.npmjs.com/package/@interop/data-integrity-core).
33
+
34
+ To actually perform encryption with those keys, we recommend you use the
35
+ [`minimal-cipher`](https://github.com/digitalbazaar/minimal-cipher) library.
36
+
37
+ This is a low-level level library to generate and serialize X25519 (Curve25519)
38
+ key pairs (uses `nacl.box` under the hood).
39
+
40
+ See also (related specs):
41
+
42
+ - [Linked Data Proofs](https://w3c-ccg.github.io/ld-proofs/)
43
+ - [Linked Data Cryptographic Suite Registry](https://w3c-ccg.github.io/ld-cryptosuite-registry/)
44
+
45
+ ## Install
46
+
47
+ Requires Node.js 24+
48
+
49
+ This is an ESM-only package (`"type": "module"`).
50
+
51
+ To install as a dependency:
52
+
53
+ ```
54
+ npm install @interop/x25519-key-agreement-key
55
+ ```
56
+
57
+ To install locally (for development):
58
+
59
+ ```
60
+ git clone https://github.com/interop-alliance/x25519-key-agreement-key.git
61
+ cd x25519-key-agreement-key
62
+ pnpm install
63
+ ```
64
+
65
+ ## Usage
66
+
67
+ Importing:
68
+
69
+ ```js
70
+ import { X25519KeyAgreementKey2020 } from '@interop/x25519-key-agreement-key'
71
+ ```
72
+
73
+ Generating:
74
+
75
+ ```js
76
+ const keyPair = await X25519KeyAgreementKey2020.generate({
77
+ controller: 'did:example:1234'
78
+ });
79
+ // ->
80
+ {
81
+ "id": "did:example:1234#z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM",
82
+ "controller": "did:example:1234",
83
+ "type": "X25519KeyAgreementKey2020",
84
+ "publicKeyMultibase": "z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM",
85
+ "privateKeyMultibase": "z3weeMD56C1T347EmB6kYNS7trpQwjvtQCpCYRpqGz6mcemT"
86
+ }
87
+
88
+ ```
89
+
90
+ Serializing just the public key:
91
+
92
+ ```js
93
+ keyPair.export({publicKey: true});
94
+ // ->
95
+ {
96
+ "id": "did:example:1234#z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM",
97
+ "controller": "did:example:1234",
98
+ "type": "X25519KeyAgreementKey2020",
99
+ "publicKeyMultibase": "z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM"
100
+ }
101
+ ```
102
+
103
+ Serializing both the private and public key:
104
+
105
+ ```js
106
+ // a different key pair than the previous example
107
+ await keyPair.export({publicKey: true, privateKey: true})
108
+ // ->
109
+ {
110
+ "id": "did:example:1234#z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM",
111
+ "controller": "did:example:1234",
112
+ "type": "X25519KeyAgreementKey2020",
113
+ "publicKeyMultibase": "z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM",
114
+ "privateKeyMultibase": "z3weeMD56C1T347EmB6kYNS7trpQwjvtQCpCYRpqGz6mcemT"
115
+ }
116
+ ```
117
+
118
+ Deserializing:
119
+
120
+ ```js
121
+ // Loading public key only
122
+ const keyPair = await X25519KeyAgreementKey2020.from({
123
+ id: 'did:example:1234#z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM',
124
+ controller: 'did:example:1234',
125
+ type: 'X25519KeyAgreementKey2020',
126
+ publicKeyMultibase: 'z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM'
127
+ })
128
+ ```
129
+
130
+ ## Contribute
131
+
132
+ See
133
+ [the contribute file](https://github.com/digitalbazaar/bedrock/blob/master/CONTRIBUTING.md)!
134
+
135
+ PRs accepted.
136
+
137
+ If editing the Readme, please conform to the
138
+ [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
139
+
140
+ ## License
141
+
142
+ - MIT License - DCC - TypeScript compatibility.
143
+ - New BSD License (3-clause) © 2020-2021 Digital Bazaar - Initial
144
+ implementation.
@@ -0,0 +1,204 @@
1
+ /*!
2
+ * Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import { AbstractKeyPair, type GenerateKeyPairOptions, type IKeyAgreementKeyPair2020, type ISigner, type IVerificationKeyPair2020, type IVerificationResult, type IVerifier } from '@interop/data-integrity-core';
5
+ /**
6
+ * A source Ed25519 verification key (2020) shape, used by the
7
+ * `fromEd25519VerificationKey2020` conversion method.
8
+ */
9
+ interface Ed25519VerificationKey2020Like {
10
+ controller?: string;
11
+ publicKeyMultibase?: string;
12
+ privateKeyMultibase?: string;
13
+ }
14
+ export declare class X25519KeyAgreementKey2020 extends AbstractKeyPair {
15
+ static suite: string;
16
+ static SUITE_CONTEXT: string;
17
+ publicKeyMultibase: string;
18
+ privateKeyMultibase?: string;
19
+ /**
20
+ * @param {object} options - Options hashmap.
21
+ * @param {string} options.controller - Controller DID or document url.
22
+ * @param {string} [options.id] - Key ID, typically composed of controller
23
+ * URL and key fingerprint as hash fragment.
24
+ * @param {string} options.publicKeyMultibase - Multibase encoded public key.
25
+ * @param {string} [options.privateKeyMultibase] - Multibase private key.
26
+ * @param {string} [options.revoked] - Timestamp of when the key has been
27
+ * revoked, in RFC3339 format. If not present, the key itself is considered
28
+ * not revoked. Note that this mechanism is slightly different than DID
29
+ * Document key revocation, where a DID controller can revoke a key from
30
+ * that DID by removing it from the DID Document.
31
+ */
32
+ constructor(options?: IKeyAgreementKeyPair2020);
33
+ /**
34
+ * Generates a new public/private X25519 Key Pair.
35
+ *
36
+ * @param {object} [options={}] - Keypair options (see controller docstring).
37
+ *
38
+ * @returns {Promise<X25519KeyAgreementKey2020>} Generated key pair.
39
+ */
40
+ static generate(options?: GenerateKeyPairOptions): Promise<X25519KeyAgreementKey2020>;
41
+ /**
42
+ * Creates an X25519KeyAgreementKey2020 Key Pair from an existing key
43
+ * (constructor method).
44
+ *
45
+ * @param {object} [options={}] - Keypair options (see controller docstring).
46
+ *
47
+ * @returns {X25519KeyAgreementKey2020} An X25519 Key Pair.
48
+ */
49
+ static from(options?: IKeyAgreementKeyPair2020 & {
50
+ publicKeyBase58?: string;
51
+ privateKeyBase58?: string;
52
+ }): Promise<X25519KeyAgreementKey2020>;
53
+ /**
54
+ * Creates an X25519KeyAgreementKey2020 Key Pair from an existing 2019 key
55
+ * (backwards compatibility method).
56
+ *
57
+ * @param {object} [options={}] - Options hashmap.
58
+ * @param {string} options.publicKeyBase58 - Base58btc encoded public key.
59
+ * @param {string} [options.privateKeyBase58] - Base58btc encoded private key.
60
+ * @param {object} [options.keyPairOptions] - Other options.
61
+ *
62
+ * @returns {Promise<X25519KeyAgreementKey2020>} 2020 Crypto suite key pair.
63
+ */
64
+ static fromX25519KeyAgreementKey2019({ publicKeyBase58, privateKeyBase58, ...keyPairOptions }?: IKeyAgreementKeyPair2020 & {
65
+ publicKeyBase58?: string;
66
+ privateKeyBase58?: string;
67
+ }): Promise<X25519KeyAgreementKey2020>;
68
+ /**
69
+ * Converts a keypair instance of type Ed25519VerificationKey2020 to an
70
+ * instance of this class.
71
+ *
72
+ * @see https://github.com/digitalbazaar/ed25519-verification-key-2020
73
+ *
74
+ * @param {object} [options={}] - Options hashmap.
75
+ * @param {Ed25519VerificationKey2020} options.keyPair - Source key pair.
76
+ *
77
+ * @returns {X25519KeyAgreementKey2020} A derived/converted key agreement
78
+ * key pair.
79
+ */
80
+ static fromEd25519VerificationKey2020({ keyPair }: {
81
+ keyPair: Ed25519VerificationKey2020Like;
82
+ }): X25519KeyAgreementKey2020;
83
+ /**
84
+ * @param {object} [options={}] - Options hashmap.
85
+ * @param {string} options.publicKeyMultibase - Multibase encoded Ed25519
86
+ * public key.
87
+ *
88
+ * @returns {string} Multibase encoded converted X25519 Public key.
89
+ */
90
+ static convertFromEdPublicKey({ publicKeyMultibase }?: {
91
+ publicKeyMultibase?: string;
92
+ }): string;
93
+ /**
94
+ * @param {object} [options={}] - Options hashmap.
95
+ * @param {string} options.privateKeyMultibase - Multibase encoded Ed25519
96
+ * private key.
97
+ *
98
+ * @returns {string} Multibase encoded converted X25519 Private key.
99
+ */
100
+ static convertFromEdPrivateKey({ privateKeyMultibase }?: {
101
+ privateKeyMultibase?: string;
102
+ }): string;
103
+ /**
104
+ * Exports the serialized representation of the KeyPair.
105
+ *
106
+ * @param {object} [options={}] - Options hashmap.
107
+ * @param {boolean} [options.publicKey] - Export public key material?
108
+ * @param {boolean} [options.privateKey] - Export private key material?
109
+ * @param {boolean} [options.includeContext] - Include JSON-LD context?
110
+ *
111
+ * @returns {object} A plain js object that's ready for serialization
112
+ * (to JSON, etc), for use in DIDs etc.
113
+ */
114
+ export({ publicKey, privateKey, includeContext }?: {
115
+ publicKey?: boolean;
116
+ privateKey?: boolean;
117
+ includeContext?: boolean;
118
+ }): IVerificationKeyPair2020;
119
+ /**
120
+ * Generates and returns a base58btc multibase encoded value of a multicodec
121
+ * X25519 public key fingerprint (for use with cryptonyms, for example).
122
+ *
123
+ * @see https://github.com/multiformats/multicodec
124
+ * @see https://github.com/multiformats/multibase
125
+ *
126
+ * @param {object} [options={}] - Options hashmap.
127
+ * @param {string} options.publicKeyMultibase - Multibase encoded public key.
128
+ *
129
+ * @returns {string} The fingerprint.
130
+ */
131
+ static fingerprintFromPublicKey({ publicKeyMultibase }?: {
132
+ publicKeyMultibase?: string;
133
+ }): string;
134
+ /**
135
+ * Creates an instance of X25519KeyAgreementKey2020 from a key fingerprint.
136
+ *
137
+ * @param {object} [options={}] - Options hashmap.
138
+ * @param {string} options.fingerprint - Public key fingerprint.
139
+ *
140
+ * @returns {X25519KeyAgreementKey2020} Key pair instance (public key material
141
+ * only) created from the fingerprint.
142
+ */
143
+ static fromFingerprint({ fingerprint }?: {
144
+ fingerprint?: string;
145
+ }): X25519KeyAgreementKey2020;
146
+ /**
147
+ * Derives a shared secret via a given public key, typically for use
148
+ * as one parameter for computing a shared key. It should not be used as
149
+ * a shared key itself, but rather as an input into a key derivation function
150
+ * (KDF) to produce a shared key.
151
+ *
152
+ * @param {object} [options={}] - Options hashmap.
153
+ * @param {LDKeyPair} options.publicKey - Remote key pair.
154
+ *
155
+ * @returns {Promise<Uint8Array>} Derived secret.
156
+ */
157
+ deriveSecret({ publicKey }: {
158
+ publicKey: {
159
+ publicKeyMultibase?: string;
160
+ };
161
+ }): Promise<Uint8Array>;
162
+ /**
163
+ * Generates and returns a multiformats encoded
164
+ * X25519 public key fingerprint (for use with cryptonyms, for example).
165
+ *
166
+ * @see https://github.com/multiformats/multicodec
167
+ *
168
+ * @returns {string} The fingerprint.
169
+ */
170
+ fingerprint(): string;
171
+ /**
172
+ * Tests whether the fingerprint was generated from a given key pair.
173
+ *
174
+ * @example
175
+ * xKeyPair.verifyFingerprint('...');
176
+ * // {valid: true};
177
+ *
178
+ * @param {object} [options={}] - Options hashmap.
179
+ * @param {string} options.fingerprint - An x25519 key fingerprint (typically
180
+ * from a key id).
181
+ *
182
+ * @returns {IVerificationResult} An object indicating whether the fingerprint
183
+ * was verified.
184
+ */
185
+ verifyFingerprint({ fingerprint }?: {
186
+ fingerprint?: string;
187
+ }): IVerificationResult;
188
+ /**
189
+ * Key agreement keys are used for ECDH (see {@link deriveSecret}), not for
190
+ * producing signatures.
191
+ *
192
+ * @returns {ISigner} Never returns; always throws.
193
+ */
194
+ signer(): ISigner;
195
+ /**
196
+ * Key agreement keys are used for ECDH (see {@link deriveSecret}), not for
197
+ * verifying signatures.
198
+ *
199
+ * @returns {IVerifier} Never returns; always throws.
200
+ */
201
+ verifier(): IVerifier;
202
+ }
203
+ export {};
204
+ //# sourceMappingURL=X25519KeyAgreementKey2020.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"X25519KeyAgreementKey2020.d.ts","sourceRoot":"","sources":["../src/X25519KeyAgreementKey2020.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,eAAe,EACf,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,OAAO,EACZ,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACf,MAAM,8BAA8B,CAAA;AAsBrC;;;GAGG;AACH,UAAU,8BAA8B;IACtC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED,qBAAa,yBAA0B,SAAQ,eAAe;IAE5D,MAAM,CAAC,KAAK,EAAE,MAAM,CAAW;IAE/B,MAAM,CAAC,aAAa,EAAE,MAAM,CACuB;IAEnD,kBAAkB,EAAE,MAAM,CAAA;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAE5B;;;;;;;;;;;;OAYG;gBACS,OAAO,GAAE,wBAA6B;IAmClD;;;;;;OAMG;WACU,QAAQ,CACnB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,yBAAyB,CAAC;IAgBrC;;;;;;;OAOG;WACU,IAAI,CACf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AAM,CAAA;KAAO,GAAG,yBAAyB;IAM5D;;;;;;;;;;OAUG;IACG,YAAY,CAAC,EACjB,SAAS,EACV,EAAE;QACD,SAAS,EAAE;YAAE,kBAAkB,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAC3C,GAAG,OAAO,CAAC,UAAU,CAAC;IAavB;;;;;;;OAOG;IACH,WAAW,IAAI,MAAM;IAIrB;;;;;;;;;;;;;OAaG;IACH,iBAAiB,CAAC,EAChB,WAAW,EACZ,GAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,mBAAmB;IAYtD;;;;;OAKG;IACH,MAAM,IAAI,OAAO;IAMjB;;;;;OAKG;IACH,QAAQ,IAAI,SAAS;CAMtB"}
@@ -0,0 +1,382 @@
1
+ /*!
2
+ * Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import { AbstractKeyPair } from '@interop/data-integrity-core';
5
+ import { ed25519 } from '@noble/curves/ed25519.js';
6
+ import { base58btc } from './baseX.js';
7
+ import { deriveSecret, ed25519SecretKeyToX25519, generateKeyPair } from './crypto.js';
8
+ const SUITE_ID = 'X25519KeyAgreementKey2020';
9
+ // multibase base58-btc header
10
+ const MULTIBASE_BASE58BTC_HEADER = 'z';
11
+ // multicodec ed25519-pub header as varint
12
+ const MULTICODEC_ED25519_PUB_HEADER = new Uint8Array([0xed, 0x01]);
13
+ // multicodec ed25519-priv header as varint
14
+ const MULTICODEC_ED25519_PRIV_HEADER = new Uint8Array([0x80, 0x26]);
15
+ // multicodec x25519-pub header as varint
16
+ const MULTICODEC_X25519_PUB_HEADER = new Uint8Array([0xec, 0x01]);
17
+ // multicodec x25519-priv header as varint
18
+ const MULTICODEC_X25519_PRIV_HEADER = new Uint8Array([0x82, 0x26]);
19
+ export class X25519KeyAgreementKey2020 extends AbstractKeyPair {
20
+ // Used by CryptoLD harness for dispatching.
21
+ static suite = SUITE_ID;
22
+ // Used by CryptoLD harness's fromKeyId() method.
23
+ static SUITE_CONTEXT = 'https://w3id.org/security/suites/x25519-2020/v1';
24
+ publicKeyMultibase;
25
+ privateKeyMultibase;
26
+ /**
27
+ * @param {object} options - Options hashmap.
28
+ * @param {string} options.controller - Controller DID or document url.
29
+ * @param {string} [options.id] - Key ID, typically composed of controller
30
+ * URL and key fingerprint as hash fragment.
31
+ * @param {string} options.publicKeyMultibase - Multibase encoded public key.
32
+ * @param {string} [options.privateKeyMultibase] - Multibase private key.
33
+ * @param {string} [options.revoked] - Timestamp of when the key has been
34
+ * revoked, in RFC3339 format. If not present, the key itself is considered
35
+ * not revoked. Note that this mechanism is slightly different than DID
36
+ * Document key revocation, where a DID controller can revoke a key from
37
+ * that DID by removing it from the DID Document.
38
+ */
39
+ constructor(options = {}) {
40
+ super(options);
41
+ this.type = SUITE_ID;
42
+ const { publicKeyMultibase, privateKeyMultibase } = options;
43
+ if (!publicKeyMultibase) {
44
+ throw new TypeError('The "publicKeyMultibase" property is required.');
45
+ }
46
+ if (!publicKeyMultibase ||
47
+ !_isValidKeyHeader(publicKeyMultibase, MULTICODEC_X25519_PUB_HEADER)) {
48
+ throw new Error('"publicKeyMultibase" has invalid header bytes: ' +
49
+ `"${publicKeyMultibase}".`);
50
+ }
51
+ if (privateKeyMultibase &&
52
+ !_isValidKeyHeader(privateKeyMultibase, MULTICODEC_X25519_PRIV_HEADER)) {
53
+ throw new Error('"privateKeyMultibase" has invalid header bytes.');
54
+ }
55
+ // assign valid key values
56
+ this.publicKeyMultibase = publicKeyMultibase;
57
+ this.privateKeyMultibase = privateKeyMultibase;
58
+ if (this.controller && !this.id) {
59
+ this.id = `${this.controller}#${this.fingerprint()}`;
60
+ }
61
+ }
62
+ /**
63
+ * Generates a new public/private X25519 Key Pair.
64
+ *
65
+ * @param {object} [options={}] - Keypair options (see controller docstring).
66
+ *
67
+ * @returns {Promise<X25519KeyAgreementKey2020>} Generated key pair.
68
+ */
69
+ static async generate(options = {}) {
70
+ const { publicKey, privateKey } = await generateKeyPair();
71
+ return new X25519KeyAgreementKey2020({
72
+ publicKeyMultibase: _multibaseEncode(MULTICODEC_X25519_PUB_HEADER, publicKey),
73
+ privateKeyMultibase: _multibaseEncode(MULTICODEC_X25519_PRIV_HEADER, privateKey),
74
+ ...options
75
+ });
76
+ }
77
+ /**
78
+ * Creates an X25519KeyAgreementKey2020 Key Pair from an existing key
79
+ * (constructor method).
80
+ *
81
+ * @param {object} [options={}] - Keypair options (see controller docstring).
82
+ *
83
+ * @returns {X25519KeyAgreementKey2020} An X25519 Key Pair.
84
+ */
85
+ static async from(options = {}) {
86
+ // Check to see if this is an X25519KeyAgreementKey2019
87
+ if (options.publicKeyBase58) {
88
+ // Convert it to a 2020 key pair instance
89
+ return this.fromX25519KeyAgreementKey2019(options);
90
+ }
91
+ return new X25519KeyAgreementKey2020(options);
92
+ }
93
+ /**
94
+ * Creates an X25519KeyAgreementKey2020 Key Pair from an existing 2019 key
95
+ * (backwards compatibility method).
96
+ *
97
+ * @param {object} [options={}] - Options hashmap.
98
+ * @param {string} options.publicKeyBase58 - Base58btc encoded public key.
99
+ * @param {string} [options.privateKeyBase58] - Base58btc encoded private key.
100
+ * @param {object} [options.keyPairOptions] - Other options.
101
+ *
102
+ * @returns {Promise<X25519KeyAgreementKey2020>} 2020 Crypto suite key pair.
103
+ */
104
+ static async fromX25519KeyAgreementKey2019({ publicKeyBase58, privateKeyBase58, ...keyPairOptions } = {}) {
105
+ let publicKeyMultibase;
106
+ let privateKeyMultibase;
107
+ if (publicKeyBase58) {
108
+ // prefix with `z` to indicate multi-base base58btc encoding
109
+ publicKeyMultibase = _multibaseEncode(MULTICODEC_X25519_PUB_HEADER, base58btc.decode(publicKeyBase58));
110
+ }
111
+ if (privateKeyBase58) {
112
+ // prefix with `z` to indicate multi-base base58btc encoding
113
+ privateKeyMultibase = _multibaseEncode(MULTICODEC_X25519_PRIV_HEADER, base58btc.decode(privateKeyBase58));
114
+ }
115
+ return new X25519KeyAgreementKey2020({
116
+ publicKeyMultibase,
117
+ privateKeyMultibase,
118
+ ...keyPairOptions
119
+ });
120
+ }
121
+ /**
122
+ * Converts a keypair instance of type Ed25519VerificationKey2020 to an
123
+ * instance of this class.
124
+ *
125
+ * @see https://github.com/digitalbazaar/ed25519-verification-key-2020
126
+ *
127
+ * @param {object} [options={}] - Options hashmap.
128
+ * @param {Ed25519VerificationKey2020} options.keyPair - Source key pair.
129
+ *
130
+ * @returns {X25519KeyAgreementKey2020} A derived/converted key agreement
131
+ * key pair.
132
+ */
133
+ static fromEd25519VerificationKey2020({ keyPair }) {
134
+ if (!keyPair.publicKeyMultibase) {
135
+ throw new Error('Source public key is required to convert.');
136
+ }
137
+ if (!keyPair.publicKeyMultibase.startsWith(MULTIBASE_BASE58BTC_HEADER)) {
138
+ throw new TypeError('Expecting "publicKeyMultibase" value to be multibase base58btc ' +
139
+ 'encoded (must start with "z").');
140
+ }
141
+ const xKey = new X25519KeyAgreementKey2020({
142
+ controller: keyPair.controller,
143
+ publicKeyMultibase: X25519KeyAgreementKey2020.convertFromEdPublicKey(keyPair)
144
+ });
145
+ if (keyPair.privateKeyMultibase) {
146
+ if (!keyPair.privateKeyMultibase.startsWith(MULTIBASE_BASE58BTC_HEADER)) {
147
+ throw new TypeError('Expecting "privateKeyMultibase" value to be multibase base58btc ' +
148
+ 'encoded (must start with "z").');
149
+ }
150
+ xKey.privateKeyMultibase =
151
+ X25519KeyAgreementKey2020.convertFromEdPrivateKey(keyPair);
152
+ }
153
+ return xKey;
154
+ }
155
+ /**
156
+ * @param {object} [options={}] - Options hashmap.
157
+ * @param {string} options.publicKeyMultibase - Multibase encoded Ed25519
158
+ * public key.
159
+ *
160
+ * @returns {string} Multibase encoded converted X25519 Public key.
161
+ */
162
+ static convertFromEdPublicKey({ publicKeyMultibase } = {}) {
163
+ if (!publicKeyMultibase) {
164
+ throw new Error('Source public key is required to convert.');
165
+ }
166
+ const edPubkeyBytes = _multibaseDecode(MULTICODEC_ED25519_PUB_HEADER, publicKeyMultibase);
167
+ // Converts a 32-byte Ed25519 public key into a 32-byte Curve25519 key.
168
+ // Throws if the given public key is not a valid Ed25519 public key.
169
+ let dhPubkeyBytes;
170
+ try {
171
+ dhPubkeyBytes = ed25519.utils.toMontgomery(edPubkeyBytes);
172
+ }
173
+ catch {
174
+ throw new Error('Error converting to X25519; Invalid Ed25519 public key.');
175
+ }
176
+ return _multibaseEncode(MULTICODEC_X25519_PUB_HEADER, dhPubkeyBytes);
177
+ }
178
+ /**
179
+ * @param {object} [options={}] - Options hashmap.
180
+ * @param {string} options.privateKeyMultibase - Multibase encoded Ed25519
181
+ * private key.
182
+ *
183
+ * @returns {string} Multibase encoded converted X25519 Private key.
184
+ */
185
+ static convertFromEdPrivateKey({ privateKeyMultibase } = {}) {
186
+ if (!privateKeyMultibase) {
187
+ throw new Error('Source private key is required to convert.');
188
+ }
189
+ const edPrivkeyBytes = _multibaseDecode(MULTICODEC_ED25519_PRIV_HEADER, privateKeyMultibase);
190
+ // Converts a 64-byte Ed25519 secret key (or just the first 32-byte part of
191
+ // it, which is the secret value) into a 32-byte Curve25519 secret key
192
+ const dhPrivkeyBytes = ed25519SecretKeyToX25519(edPrivkeyBytes);
193
+ // note: a future version should make this method async to allow use of
194
+ // noble to convert private keys -- but the tweetnacl version used
195
+ // internally is much faster (~ x100):
196
+ // const {head: dhPrivkeyBytes} = await utils.getExtendedPublicKey(
197
+ // edPrivkeyBytes.slice(0, 32));
198
+ if (!dhPrivkeyBytes) {
199
+ throw new Error('Error converting to X25519; Invalid Ed25519 private key.');
200
+ }
201
+ return _multibaseEncode(MULTICODEC_X25519_PRIV_HEADER, dhPrivkeyBytes);
202
+ }
203
+ /**
204
+ * Exports the serialized representation of the KeyPair.
205
+ *
206
+ * @param {object} [options={}] - Options hashmap.
207
+ * @param {boolean} [options.publicKey] - Export public key material?
208
+ * @param {boolean} [options.privateKey] - Export private key material?
209
+ * @param {boolean} [options.includeContext] - Include JSON-LD context?
210
+ *
211
+ * @returns {object} A plain js object that's ready for serialization
212
+ * (to JSON, etc), for use in DIDs etc.
213
+ */
214
+ export({ publicKey = false, privateKey = false, includeContext = false } = {}) {
215
+ if (!(publicKey || privateKey)) {
216
+ throw new TypeError('Export requires specifying either "publicKey" or "privateKey".');
217
+ }
218
+ const exportedKey = {
219
+ id: this.id,
220
+ type: this.type
221
+ };
222
+ if (includeContext) {
223
+ exportedKey['@context'] = X25519KeyAgreementKey2020.SUITE_CONTEXT;
224
+ }
225
+ if (this.controller) {
226
+ exportedKey.controller = this.controller;
227
+ }
228
+ if (publicKey) {
229
+ exportedKey.publicKeyMultibase = this.publicKeyMultibase;
230
+ }
231
+ if (privateKey) {
232
+ exportedKey.privateKeyMultibase = this.privateKeyMultibase;
233
+ }
234
+ if (this.revoked) {
235
+ exportedKey.revoked = this.revoked;
236
+ }
237
+ return exportedKey;
238
+ }
239
+ /**
240
+ * Generates and returns a base58btc multibase encoded value of a multicodec
241
+ * X25519 public key fingerprint (for use with cryptonyms, for example).
242
+ *
243
+ * @see https://github.com/multiformats/multicodec
244
+ * @see https://github.com/multiformats/multibase
245
+ *
246
+ * @param {object} [options={}] - Options hashmap.
247
+ * @param {string} options.publicKeyMultibase - Multibase encoded public key.
248
+ *
249
+ * @returns {string} The fingerprint.
250
+ */
251
+ static fingerprintFromPublicKey({ publicKeyMultibase } = {}) {
252
+ if (!publicKeyMultibase) {
253
+ throw new Error('Source public key is required.');
254
+ }
255
+ return publicKeyMultibase;
256
+ }
257
+ /**
258
+ * Creates an instance of X25519KeyAgreementKey2020 from a key fingerprint.
259
+ *
260
+ * @param {object} [options={}] - Options hashmap.
261
+ * @param {string} options.fingerprint - Public key fingerprint.
262
+ *
263
+ * @returns {X25519KeyAgreementKey2020} Key pair instance (public key material
264
+ * only) created from the fingerprint.
265
+ */
266
+ static fromFingerprint({ fingerprint } = {}) {
267
+ return new X25519KeyAgreementKey2020({
268
+ publicKeyMultibase: fingerprint
269
+ });
270
+ }
271
+ /**
272
+ * Derives a shared secret via a given public key, typically for use
273
+ * as one parameter for computing a shared key. It should not be used as
274
+ * a shared key itself, but rather as an input into a key derivation function
275
+ * (KDF) to produce a shared key.
276
+ *
277
+ * @param {object} [options={}] - Options hashmap.
278
+ * @param {LDKeyPair} options.publicKey - Remote key pair.
279
+ *
280
+ * @returns {Promise<Uint8Array>} Derived secret.
281
+ */
282
+ async deriveSecret({ publicKey }) {
283
+ const remotePublicKey = _multibaseDecode(MULTICODEC_X25519_PUB_HEADER, publicKey.publicKeyMultibase);
284
+ const privateKey = _multibaseDecode(MULTICODEC_X25519_PRIV_HEADER, this.privateKeyMultibase);
285
+ return deriveSecret({ privateKey, remotePublicKey });
286
+ }
287
+ /**
288
+ * Generates and returns a multiformats encoded
289
+ * X25519 public key fingerprint (for use with cryptonyms, for example).
290
+ *
291
+ * @see https://github.com/multiformats/multicodec
292
+ *
293
+ * @returns {string} The fingerprint.
294
+ */
295
+ fingerprint() {
296
+ return this.publicKeyMultibase;
297
+ }
298
+ /**
299
+ * Tests whether the fingerprint was generated from a given key pair.
300
+ *
301
+ * @example
302
+ * xKeyPair.verifyFingerprint('...');
303
+ * // {valid: true};
304
+ *
305
+ * @param {object} [options={}] - Options hashmap.
306
+ * @param {string} options.fingerprint - An x25519 key fingerprint (typically
307
+ * from a key id).
308
+ *
309
+ * @returns {IVerificationResult} An object indicating whether the fingerprint
310
+ * was verified.
311
+ */
312
+ verifyFingerprint({ fingerprint } = {}) {
313
+ // fingerprint should have `z` prefix indicating
314
+ // that it's base58btc multibase encoded
315
+ if (!_isValidKeyHeader(fingerprint, MULTICODEC_X25519_PUB_HEADER)) {
316
+ throw new Error(`"fingerprint" has invalid header bytes: "${fingerprint}".`);
317
+ }
318
+ return { verified: true };
319
+ }
320
+ /**
321
+ * Key agreement keys are used for ECDH (see {@link deriveSecret}), not for
322
+ * producing signatures.
323
+ *
324
+ * @returns {ISigner} Never returns; always throws.
325
+ */
326
+ signer() {
327
+ throw new Error('X25519KeyAgreementKey2020 is a key agreement key and cannot sign.');
328
+ }
329
+ /**
330
+ * Key agreement keys are used for ECDH (see {@link deriveSecret}), not for
331
+ * verifying signatures.
332
+ *
333
+ * @returns {IVerifier} Never returns; always throws.
334
+ */
335
+ verifier() {
336
+ throw new Error('X25519KeyAgreementKey2020 is a key agreement key and cannot verify ' +
337
+ 'signatures.');
338
+ }
339
+ }
340
+ /**
341
+ * Checks to see if the given value is a valid multibase encoded key.
342
+ *
343
+ * @param {Uint8Array} multibaseKey - The multibase-encoded key value.
344
+ * @param {Uint8Array} expectedHeader - The expected header for the key value.
345
+ * @returns {boolean} Returns true if the header is valid, false otherwise.
346
+ */
347
+ function _isValidKeyHeader(multibaseKey, expectedHeader) {
348
+ if (!(typeof multibaseKey === 'string' &&
349
+ multibaseKey[0] === MULTIBASE_BASE58BTC_HEADER)) {
350
+ return false;
351
+ }
352
+ const keyBytes = base58btc.decode(multibaseKey.slice(1));
353
+ return expectedHeader.every((val, i) => keyBytes[i] === val);
354
+ }
355
+ /**
356
+ * Encodes a given Uint8Array to multibase-encoded string.
357
+ *
358
+ * @param {Uint8Array} header - Multicodec header to prepend to the bytes.
359
+ * @param {Uint8Array} bytes - Bytes to encode.
360
+ * @returns {string} Multibase-encoded string.
361
+ */
362
+ function _multibaseEncode(header, bytes) {
363
+ const mcBytes = new Uint8Array(header.length + bytes.length);
364
+ mcBytes.set(header);
365
+ mcBytes.set(bytes, header.length);
366
+ return MULTIBASE_BASE58BTC_HEADER + base58btc.encode(mcBytes);
367
+ }
368
+ /**
369
+ * Decodes a given string as a multibase-encoded multicodec value.
370
+ *
371
+ * @param {Uint8Array} header - Expected header bytes for the multicodec value.
372
+ * @param {string} text - Multibase encoded string to decode.
373
+ * @returns {Uint8Array} Decoded bytes.
374
+ */
375
+ function _multibaseDecode(header, text) {
376
+ const mcValue = base58btc.decode(text.substr(1));
377
+ if (!header.every((val, i) => mcValue[i] === val)) {
378
+ throw new Error('Multibase value does not have expected header.');
379
+ }
380
+ return mcValue.slice(header.length);
381
+ }
382
+ //# sourceMappingURL=X25519KeyAgreementKey2020.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"X25519KeyAgreementKey2020.js","sourceRoot":"","sources":["../src/X25519KeyAgreementKey2020.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,eAAe,EAOhB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EACL,YAAY,EACZ,wBAAwB,EACxB,eAAe,EAChB,MAAM,aAAa,CAAA;AAEpB,MAAM,QAAQ,GAAG,2BAA2B,CAAA;AAC5C,8BAA8B;AAC9B,MAAM,0BAA0B,GAAG,GAAG,CAAA;AACtC,0CAA0C;AAC1C,MAAM,6BAA6B,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAClE,2CAA2C;AAC3C,MAAM,8BAA8B,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AACnE,yCAAyC;AACzC,MAAM,4BAA4B,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AACjE,0CAA0C;AAC1C,MAAM,6BAA6B,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAYlE,MAAM,OAAO,yBAA0B,SAAQ,eAAe;IAC5D,4CAA4C;IAC5C,MAAM,CAAC,KAAK,GAAW,QAAQ,CAAA;IAC/B,iDAAiD;IACjD,MAAM,CAAC,aAAa,GAClB,iDAAiD,CAAA;IAEnD,kBAAkB,CAAQ;IAC1B,mBAAmB,CAAS;IAE5B;;;;;;;;;;;;OAYG;IACH,YAAY,UAAoC,EAAE;QAChD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAA;QACpB,MAAM,EA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AAC"}
@@ -0,0 +1,2 @@
1
+ export declare const base58btc: import("@scure/base").BytesCoder;
2
+ //# sourceMappingURL=baseX.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseX.d.ts","sourceRoot":"","sources":["../src/baseX.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,kCAAS,CAAA"}
package/dist/baseX.js ADDED
@@ -0,0 +1,3 @@
1
+ import { base58 } from '@scure/base';
2
+ export const base58btc = base58;
3
+ //# sourceMappingURL=baseX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseX.js","sourceRoot":"","sources":["../src/baseX.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAA"}
@@ -0,0 +1,5 @@
1
+ /*!
2
+ * Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ export { deriveSecret, generateKeyPair, ed25519SecretKeyToX25519 } from './crypto-nacl.js';
5
+ //# 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,OAAO,EACL,YAAY,EACZ,eAAe,EACf,wBAAwB,EACzB,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,5 @@
1
+ /*!
2
+ * Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ export { deriveSecret, generateKeyPair, ed25519SecretKeyToX25519 } from './crypto-nacl.js';
5
+ //# 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,OAAO,EACL,YAAY,EACZ,eAAe,EACf,wBAAwB,EACzB,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Note: The following two functions are async to match the signature of
3
+ * their native Node.js counterparts (see './crypto.js').
4
+ */
5
+ export declare function deriveSecret({ privateKey, remotePublicKey }: {
6
+ privateKey: Uint8Array;
7
+ remotePublicKey: Uint8Array;
8
+ }): Promise<Uint8Array>;
9
+ export declare function generateKeyPair(): Promise<{
10
+ publicKey: Uint8Array;
11
+ privateKey: Uint8Array;
12
+ }>;
13
+ export declare function ed25519SecretKeyToX25519(secretKey: Uint8Array): Uint8Array;
14
+ //# sourceMappingURL=crypto-nacl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-nacl.d.ts","sourceRoot":"","sources":["../src/crypto-nacl.ts"],"names":[],"mappings":"AAKA;;;GAGG;AAEH,wBAAsB,YAAY,CAAC,EACjC,UAAU,EACV,eAAe,EAChB,EAAE;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,eAAe,EAAE,UAAU,CAAA;CAC5B,GAAG,OAAO,CAAC,UAAU,CAAC,CAEtB;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC;IAC/C,SAAS,EAAE,UAAU,CAAA;IACrB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAC,CAID;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,UAAU,GAAG,UAAU,CAiB1E"}
@@ -0,0 +1,31 @@
1
+ /*!
2
+ * Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import nacl from 'tweetnacl';
5
+ /**
6
+ * Note: The following two functions are async to match the signature of
7
+ * their native Node.js counterparts (see './crypto.js').
8
+ */
9
+ export async function deriveSecret({ privateKey, remotePublicKey }) {
10
+ return nacl.scalarMult(privateKey, remotePublicKey);
11
+ }
12
+ export async function generateKeyPair() {
13
+ // Each is a Uint8Array with 32-byte key
14
+ const { publicKey, secretKey: privateKey } = nacl.box.keyPair();
15
+ return { publicKey, privateKey };
16
+ }
17
+ export function ed25519SecretKeyToX25519(secretKey) {
18
+ const hash = new Uint8Array(64);
19
+ // X25519 secret key is the first 32 bytes of the hash with clamped values.
20
+ // `nacl.lowlevel` is not covered by tweetnacl's published type definitions.
21
+ const { lowlevel } = nacl;
22
+ lowlevel.crypto_hash(hash, secretKey, 32);
23
+ hash[0] &= 248;
24
+ hash[31] &= 127;
25
+ hash[31] |= 64;
26
+ const x25519SecretKey = hash.slice(0, 32);
27
+ // zero-fill remainder of hash before returning
28
+ hash.fill(0, 32);
29
+ return x25519SecretKey;
30
+ }
31
+ //# sourceMappingURL=crypto-nacl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-nacl.js","sourceRoot":"","sources":["../src/crypto-nacl.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B;;;GAGG;AAEH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,EACjC,UAAU,EACV,eAAe,EAIhB;IACC,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,eAAe,CAAC,CAAA;AACrD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe;IAInC,wCAAwC;IACxC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAA;IAC/D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAA;AAClC,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,SAAqB;IAC5D,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAA;IAC/B,2EAA2E;IAC3E,4EAA4E;IAC5E,MAAM,EAAE,QAAQ,EAAE,GAAG,IAIpB,CAAA;IACD,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,CAAA;IACzC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAA;IACd,IAAI,CAAC,EAAE,CAAC,IAAI,GAAG,CAAA;IACf,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;IACd,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IACzC,+CAA+C;IAC/C,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAChB,OAAO,eAAe,CAAA;AACxB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import * as cryptoNacl from './crypto-nacl.js';
2
+ declare let deriveSecret: (options: {
3
+ privateKey: Uint8Array;
4
+ remotePublicKey: Uint8Array;
5
+ }) => Promise<Uint8Array>;
6
+ declare let generateKeyPair: () => Promise<{
7
+ publicKey: Uint8Array;
8
+ privateKey: Uint8Array;
9
+ }>;
10
+ export { deriveSecret, generateKeyPair };
11
+ declare const ed25519SecretKeyToX25519: typeof cryptoNacl.ed25519SecretKeyToX25519;
12
+ export { ed25519SecretKeyToX25519 };
13
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAA;AAiD9C,QAAA,IAAI,YAAY,EAAE,CAAC,OAAO,EAAE;IAC1B,UAAU,EAAE,UAAU,CAAA;IACtB,eAAe,EAAE,UAAU,CAAA;CAC5B,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;AACzB,QAAA,IAAI,eAAe,EAAE,MAAM,OAAO,CAAC;IACjC,SAAS,EAAE,UAAU,CAAA;IACrB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAC,CAAA;AASF,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,CAAA;AAExC,QAAA,MAAQ,wBAAwB,4CAAe,CAAA;AAC/C,OAAO,EAAE,wBAAwB,EAAE,CAAA"}
package/dist/crypto.js ADDED
@@ -0,0 +1,52 @@
1
+ /*!
2
+ * Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import * as crypto from 'crypto';
5
+ import * as cryptoNacl from './crypto-nacl.js';
6
+ import { promisify } from 'util';
7
+ const PUBLIC_KEY_DER_PREFIX = new Uint8Array([
8
+ 48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0
9
+ ]);
10
+ const PRIVATE_KEY_DER_PREFIX = new Uint8Array([
11
+ 48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 110, 4, 34, 4, 32
12
+ ]);
13
+ async function deriveSecretNative({ privateKey, remotePublicKey }) {
14
+ const nodePrivateKey = crypto.createPrivateKey({
15
+ key: Buffer.concat([PRIVATE_KEY_DER_PREFIX, privateKey]),
16
+ format: 'der',
17
+ type: 'pkcs8'
18
+ });
19
+ const nodePublicKey = crypto.createPublicKey({
20
+ key: Buffer.concat([PUBLIC_KEY_DER_PREFIX, remotePublicKey]),
21
+ format: 'der',
22
+ type: 'spki'
23
+ });
24
+ return crypto.diffieHellman({
25
+ privateKey: nodePrivateKey,
26
+ publicKey: nodePublicKey
27
+ });
28
+ }
29
+ async function generateKeyPairNative() {
30
+ const generateKeyPairAsync = promisify(crypto.generateKeyPair);
31
+ const { publicKey: publicDerBytes, privateKey: privateDerBytes } = await generateKeyPairAsync('x25519', {
32
+ publicKeyEncoding: { format: 'der', type: 'spki' },
33
+ privateKeyEncoding: { format: 'der', type: 'pkcs8' }
34
+ });
35
+ const publicKey = publicDerBytes.slice(12, 12 + 32);
36
+ const privateKey = privateDerBytes.slice(16, 16 + 32);
37
+ return { publicKey, privateKey };
38
+ }
39
+ let deriveSecret;
40
+ let generateKeyPair;
41
+ if (typeof crypto.diffieHellman === 'function') {
42
+ deriveSecret = deriveSecretNative;
43
+ generateKeyPair = generateKeyPairNative;
44
+ }
45
+ else {
46
+ deriveSecret = cryptoNacl.deriveSecret;
47
+ generateKeyPair = cryptoNacl.generateKeyPair;
48
+ }
49
+ export { deriveSecret, generateKeyPair };
50
+ const { ed25519SecretKeyToX25519 } = cryptoNacl;
51
+ export { ed25519SecretKey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greementKey2020.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ /*!
2
+ * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ export { X25519KeyAgreementKey2020 } from './X25519KeyAgreementKey2020.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA"}
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@interop/x25519-key-agreement-key",
3
+ "version": "4.0.0",
4
+ "description": "An X25519 (Curve25519) DH (Diffie-Hellman) key implementation to work with the X25519 2020 Crypto suite.",
5
+ "homepage": "https://github.com/interop-alliance/x25519-key-agreement-key",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/interop-alliance/x25519-key-agreement-key"
9
+ },
10
+ "license": "BSD-3-Clause",
11
+ "type": "module",
12
+ "files": [
13
+ "dist",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "module": "dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "react-native": "./dist/index.js",
23
+ "import": "./dist/index.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "browser": {
28
+ "buffer": false,
29
+ "crypto": false,
30
+ "util": false,
31
+ "./dist/crypto.js": "./dist/crypto-browser.js"
32
+ },
33
+ "react-native": {
34
+ "buffer": false,
35
+ "crypto": false,
36
+ "util": false,
37
+ "./dist/crypto.js": "./dist/crypto-nacl.js"
38
+ },
39
+ "sideEffects": false,
40
+ "dependencies": {
41
+ "@interop/data-integrity-core": "^6.1.1",
42
+ "@noble/curves": "^2.2.0",
43
+ "@scure/base": "^2.2.0",
44
+ "tweetnacl": "^1.0.3"
45
+ },
46
+ "devDependencies": {
47
+ "@digitalbazaar/x25519-key-agreement-key-2019": "^6.0.0",
48
+ "@digitalcredentials/ed25519-verification-key-2020": "^5.0.0",
49
+ "@eslint/js": "^10.0.1",
50
+ "@playwright/test": "^1.60.0",
51
+ "@types/node": "^25.9.1",
52
+ "@vitest/coverage-v8": "^4.1.7",
53
+ "eslint": "^10.4.0",
54
+ "eslint-config-prettier": "^10.1.8",
55
+ "globals": "^17.6.0",
56
+ "prettier": "^3.8.3",
57
+ "rimraf": "^6.1.3",
58
+ "typescript": "^5.9.3",
59
+ "typescript-eslint": "^8.59.4",
60
+ "vite": "^8.0.14",
61
+ "vitest": "^4.1.7"
62
+ },
63
+ "publishConfig": {
64
+ "access": "public"
65
+ },
66
+ "engines": {
67
+ "node": ">=24.0"
68
+ },
69
+ "keywords": [
70
+ "Decentralized",
71
+ "Linked Data"
72
+ ],
73
+ "packageManager": "pnpm@11.3.0",
74
+ "scripts": {
75
+ "build": "pnpm run clear && tsc",
76
+ "clear": "rimraf dist/*",
77
+ "dev": "vite",
78
+ "fix": "eslint --fix src test && pnpm run format",
79
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"*.md\"",
80
+ "lint": "eslint src test",
81
+ "prepare": "pnpm run build",
82
+ "rebuild": "pnpm run clear && pnpm run build",
83
+ "test": "pnpm run fix && pnpm run lint && pnpm run test-node && pnpm run test-browser",
84
+ "test-node": "vitest run",
85
+ "test-browser": "playwright test",
86
+ "test-coverage": "vitest run --coverage"
87
+ }
88
+ }