@did-btcr2/keypair 0.5.1

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.
@@ -0,0 +1,283 @@
1
+ import { BIP340_PUBLIC_KEY_MULTIBASE_PREFIX, BIP340_PUBLIC_KEY_MULTIBASE_PREFIX_HASH, CURVE, PublicKeyError } from '@did-btcr2/common';
2
+ import { sha256 } from '@noble/hashes/sha2';
3
+ import { base58btc } from 'multiformats/bases/base58';
4
+ import { SecretKey } from './secret.js';
5
+ /**
6
+ * Encapsulates a secp256k1 public key compliant to BIP-340 BIP schnorr signature scheme.
7
+ * Provides get methods for different formats (compressed, x-only, multibase).
8
+ * Provides helpers methods for comparison and serialization.
9
+ * @class PublicKey
10
+ * @type {PublicKey}
11
+ */
12
+ export class PublicKey {
13
+ /** @type {KeyBytes} The public key bytes */
14
+ _bytes;
15
+ /** @type {MultibaseObject} The public key as a MultibaseObject */
16
+ _multibase = {
17
+ prefix: BIP340_PUBLIC_KEY_MULTIBASE_PREFIX,
18
+ key: [],
19
+ address: ''
20
+ };
21
+ /**
22
+ * Creates a PublicKey instance.
23
+ * @param {KeyBytes} bytes The public key byte array.
24
+ * @throws {PublicKeyError} if the byte length is not 32 (x-only) or 33 (compressed)
25
+ */
26
+ constructor(bytes) {
27
+ // If the byte length is not 33, throw an error
28
+ if (bytes.length !== 33) {
29
+ throw new PublicKeyError('Invalid argument: byte length must be 33 (compressed)', 'CONSTRUCTOR_ERROR', { bytes });
30
+ }
31
+ // Set the bytes
32
+ this._bytes = bytes;
33
+ // Set multibase
34
+ this._multibase.address = this.encode();
35
+ this._multibase.key = [...this._multibase.prefix, ...this.compressed];
36
+ }
37
+ /**
38
+ * Get the compressed public key.
39
+ * @returns {KeyBytes} The 33-byte compressed public key (0x02 or 0x03, x).
40
+ */
41
+ get compressed() {
42
+ const bytes = new Uint8Array(this._bytes);
43
+ return bytes;
44
+ }
45
+ ;
46
+ /**
47
+ * Get the uncompressed public key.
48
+ * @returns {Uint8Array} The 65-byte uncompressed public key (0x04, x, y).
49
+ */
50
+ get uncompressed() {
51
+ const uncompressed = this.liftX();
52
+ return uncompressed;
53
+ }
54
+ /**
55
+ * Get the parity byte of the public key.
56
+ * @returns {number} The parity byte of the public key.
57
+ */
58
+ get parity() {
59
+ const parity = this.compressed[0];
60
+ return parity;
61
+ }
62
+ /**
63
+ * Get the x-coordinate of the public key.
64
+ * @returns {Uint8Array} The 32-byte x-coordinate of the public key.
65
+ */
66
+ get x() {
67
+ const x = this.compressed.slice(1, 33);
68
+ return x;
69
+ }
70
+ /**
71
+ * Get the y-coordinate of the public key.
72
+ * @returns {Uint8Array} The 32-byte y-coordinate of the public key.
73
+ */
74
+ get y() {
75
+ const y = this.uncompressed.slice(33, 65);
76
+ return y;
77
+ }
78
+ /**
79
+ * Get the multibase public key.
80
+ * @returns {MultibaseObject} An object containing the multibase bytes, address and prefix.
81
+ */
82
+ get multibase() {
83
+ const multibase = this._multibase;
84
+ return multibase;
85
+ }
86
+ /**
87
+ * Returns the raw public key as a hex string.
88
+ * @returns {Hex} The public key as a hex string.
89
+ */
90
+ get hex() {
91
+ const hex = Buffer.from(this.compressed).toString('hex');
92
+ return hex;
93
+ }
94
+ /**
95
+ * Return the public key point.
96
+ * @returns {Point} The public key point.
97
+ */
98
+ get point() {
99
+ return {
100
+ x: this.x,
101
+ y: this.y
102
+ };
103
+ }
104
+ /**
105
+ * Returns the point of the public key.
106
+ * @param {Hex} pk The public key in hex (Uint8Array or string) format.
107
+ * @returns {Point} The point of the public key.
108
+ * @throws {PublicKeyError} If the public key is not a valid hex string or byte array.
109
+ */
110
+ static point(pk) {
111
+ // If the public key is a hex string, convert it to a PublicKey object and return the point
112
+ if (typeof pk === 'string' && /^[0-9a-fA-F]+$/.test(pk)) {
113
+ const publicKey = new PublicKey(Buffer.fromHex(pk));
114
+ return publicKey.point;
115
+ }
116
+ // If the public key is a byte array or ArrayBuffer, convert it to a PublicKey object and return the point
117
+ if (pk instanceof Uint8Array || ArrayBuffer.isView(pk)) {
118
+ const publicKey = new PublicKey(pk);
119
+ return publicKey.point;
120
+ }
121
+ // If the public key is neither a hex string nor a byte array, throw an error
122
+ throw new PublicKeyError('Invalid publicKey: must be a hex string or byte array', 'POINT_ERROR', { publicKey: pk });
123
+ }
124
+ /**
125
+ * Decodes the multibase string to the 35-byte corresponding public key (2 byte prefix + 32 byte public key).
126
+ * @returns {KeyBytes} The decoded public key: prefix and public key bytes
127
+ */
128
+ decode() {
129
+ // Decode the public key multibase string
130
+ const decoded = base58btc.decode(this.multibase.address);
131
+ // If the public key bytes are not 35 bytes, throw an error
132
+ if (decoded.length !== 35) {
133
+ throw new PublicKeyError('Invalid argument: must be 35 byte publicKeyMultibase', 'DECODE_MULTIBASE_ERROR');
134
+ }
135
+ // Grab the prefix bytes
136
+ const prefix = decoded.slice(0, 2);
137
+ // Compute the prefix hash
138
+ const prefixHash = Buffer.from(sha256(prefix)).toString('hex');
139
+ // If the prefix hash does not equal the BIP340 prefix hash, throw an error
140
+ if (prefixHash !== BIP340_PUBLIC_KEY_MULTIBASE_PREFIX_HASH) {
141
+ throw new PublicKeyError(`Invalid prefix: malformed multibase prefix ${prefix}`, 'DECODE_MULTIBASE_ERROR');
142
+ }
143
+ // Return the decoded public key bytes
144
+ return decoded;
145
+ }
146
+ /**
147
+ * Encodes compressed secp256k1 public key from bytes to BIP340 multibase format.
148
+ * @returns {string} The public key encoded in base-58-btc multibase format.
149
+ */
150
+ encode() {
151
+ // Convert public key bytes to an array
152
+ const pk = this.compressed.toArray();
153
+ // Ensure the public key is 33-byte secp256k1 compressed public key
154
+ if (pk.length !== 33) {
155
+ throw new PublicKeyError('Invalid argument: must be 33-byte (compressed) public key', 'ENCODE_MULTIBASE_ERROR');
156
+ }
157
+ // Convert prefix to an array
158
+ const publicKeyMultibase = BIP340_PUBLIC_KEY_MULTIBASE_PREFIX.toArray();
159
+ // Push the public key bytes at the end of the prefix
160
+ publicKeyMultibase.push(...pk);
161
+ // Encode the bytes in base58btc format and return
162
+ return base58btc.encode(publicKeyMultibase.toUint8Array());
163
+ }
164
+ /**
165
+ * Compares this public key to another public key.
166
+ * @param {PublicKey} other The other public key to compare
167
+ * @returns {boolean} True if the public keys are equal, false otherwise.
168
+ */
169
+ equals(other) {
170
+ return this.hex === other.hex;
171
+ }
172
+ /**
173
+ * JSON representation of a PublicKey object.
174
+ * @returns {PublicKeyObject} The PublicKey as a JSON object.
175
+ */
176
+ json() {
177
+ return {
178
+ hex: this.hex,
179
+ multibase: this.multibase,
180
+ point: {
181
+ x: this.x.toArray(),
182
+ y: this.y.toArray(),
183
+ parity: this.parity,
184
+ },
185
+ };
186
+ }
187
+ /**
188
+ * Creates a PublicKey object from a JSON representation.
189
+ * @param {PublicKeyObject} json The JSON object to initialize the PublicKey.
190
+ * @returns {PublicKey} The initialized PublicKey object.
191
+ */
192
+ static fromJSON(json) {
193
+ json.x.unshift(json.parity);
194
+ return new PublicKey(json.x.toUint8Array());
195
+ }
196
+ /**
197
+ * Computes the deterministic public key for a given private key.
198
+ * @param {PrivateKey | KeyBytes} sk The PrivateKey object or the private key bytes
199
+ * @returns {PublicKey} A new PublicKey object
200
+ */
201
+ static fromSecretKey(sk) {
202
+ // If the private key is a PrivateKey object, get the raw bytes else use the bytes
203
+ const bytes = sk instanceof SecretKey ? sk.bytes : sk;
204
+ // Throw error if the private key is not 32 bytes
205
+ if (bytes.length !== 32) {
206
+ throw new PublicKeyError('Invalid arg: must be 32 byte private key', 'FROM_PRIVATE_KEY_ERROR');
207
+ }
208
+ // Compute the public key from the private key
209
+ const privateKey = sk instanceof SecretKey ? sk : new SecretKey(sk);
210
+ // Return a new PublicKey object
211
+ return new PublicKey(privateKey.computePublicKey());
212
+ }
213
+ /**
214
+ * Computes modular exponentiation: (base^exp) % mod.
215
+ * Used for computing modular square roots.
216
+ * @param {bigint} base The base value
217
+ * @param {bigint} exp The exponent value
218
+ * @param {bigint} mod The modulus value
219
+ * @returns {bigint} The result of the modular exponentiation
220
+ */
221
+ modPow(base, exp, mod) {
222
+ let result = 1n;
223
+ while (exp > 0n) {
224
+ if (exp & 1n)
225
+ result = (result * base) % mod;
226
+ base = (base * base) % mod;
227
+ exp >>= 1n;
228
+ }
229
+ return result;
230
+ }
231
+ ;
232
+ /**
233
+ * Computes `sqrt(a) mod p` using Tonelli-Shanks algorithm.
234
+ * This finds `y` such that `y^2 ≡ a mod p`.
235
+ * @param {bigint} a The value to find the square root of
236
+ * @param {bigint} p The prime modulus
237
+ * @returns {bigint} The square root of `a` mod `p`
238
+ */
239
+ sqrtMod(a, p) {
240
+ return this.modPow(a, (p + 1n) >> 2n, p);
241
+ }
242
+ ;
243
+ /**
244
+ * Lifts a 32-byte x-only coordinate into a full secp256k1 point (x, y).
245
+ * @param xBytes 32-byte x-coordinate
246
+ * @returns {Uint8Array} 65-byte uncompressed public key (starts with `0x04`)
247
+ */
248
+ liftX() {
249
+ // Ensure x-coordinate is 32 bytes
250
+ if (this.x.length !== 32) {
251
+ throw new PublicKeyError('Invalid argument: x-coordinate length must be 32 bytes', 'LIFT_X_ERROR');
252
+ }
253
+ // Convert x from Uint8Array → BigInt
254
+ const x = BigInt('0x' + Buffer.from(this.x).toString('hex'));
255
+ if (x <= 0n || x >= CURVE.p) {
256
+ throw new PublicKeyError('Invalid conversion: x out of range as BigInt', 'LIFT_X_ERROR');
257
+ }
258
+ // Compute y² = x³ + 7 mod p
259
+ const ySquared = BigInt((x ** 3n + CURVE.b) % CURVE.p);
260
+ // Compute y (do not enforce parity)
261
+ const y = this.sqrtMod(ySquared, CURVE.p);
262
+ // Convert x and y to Uint8Array
263
+ const yBytes = Buffer.fromHex(y.toString(16).padStart(64, '0'));
264
+ // Return 65-byte uncompressed public key: `0x04 || x || y`
265
+ return new Uint8Array(Buffer.concat([Buffer.from([0x04]), Buffer.from(this.x), yBytes]));
266
+ }
267
+ ;
268
+ /**
269
+ * Static version of liftX method.
270
+ * @param {KeyBytes} x The 32-byte x-coordinate to lift.
271
+ * @returns {Uint8Array} The 65-byte uncompressed public key (0x04, x, y).
272
+ */
273
+ static xOnly(x) {
274
+ // Ensure x-coordinate is 32 bytes
275
+ if (x.length !== 32) {
276
+ throw new PublicKeyError('Invalid argument: x-coordinate length must be 32 bytes', 'LIFT_X_ERROR');
277
+ }
278
+ // Create a PublicKey instance and lift the x-coordinate
279
+ const publicKey = new PublicKey(x);
280
+ return publicKey.x;
281
+ }
282
+ }
283
+ //# sourceMappingURL=public.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public.js","sourceRoot":"","sources":["../../src/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,EAClC,uCAAuC,EACvC,KAAK,EAKL,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAiFxC;;;;;;GAMG;AACH,MAAM,OAAO,SAAS;IACpB,4CAA4C;IAC3B,MAAM,CAAW;IAElC,kEAAkE;IAC1D,UAAU,GAAoB;QACpC,MAAM,EAAI,kCAAkC;QAC5C,GAAG,EAAO,EAAE;QACZ,OAAO,EAAG,EAAE;KACb,CAAC;IAEF;;;;OAIG;IACH,YAAY,KAAe;QACzB,+CAA+C;QAC/C,IAAG,KAAK,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACvB,MAAM,IAAI,cAAc,CACtB,uDAAuD,EACvD,mBAAmB,EAAE,EAAE,KAAK,EAAE,CAC/B,CAAC;QACJ,CAAC;QACD,gBAAgB;QAChB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEpB,gBAAgB;QAChB,IAAI,CAAC,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACxC,IAAI,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,CA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AM,SAAS,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;QACnC,OAAO,SAAS,CAAC,CAAC,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,271 @@
1
+ import { BIP340_SECRET_KEY_MULTIBASE_PREFIX, BIP340_SECRET_KEY_MULTIBASE_PREFIX_HASH, CURVE, SecretKeyError } from '@did-btcr2/common';
2
+ import { sha256 } from '@noble/hashes/sha2';
3
+ import { getRandomValues } from 'crypto';
4
+ import { base58btc } from 'multiformats/bases/base58';
5
+ import * as tinysecp from 'tiny-secp256k1';
6
+ import { SchnorrKeyPair } from './pair.js';
7
+ /**
8
+ * Encapsulates a secp256k1 secret key
9
+ * Provides get methods for different formats (raw, secret, point).
10
+ * Provides helpers methods for comparison, serialization and publicKey generation.
11
+ * @class SecretKey
12
+ * @type {SecretKey}
13
+ *
14
+ */
15
+ export class SecretKey {
16
+ /** @type {KeyBytes} The entropy for the secret key as a byte array */
17
+ _bytes;
18
+ /** @type {bigint} The entropy for the secret key as a bigint */
19
+ _seed;
20
+ /** @type {string} The secret key as a secretKeyMultibase */
21
+ _multibase;
22
+ /**
23
+ * Instantiates an instance of SecretKey.
24
+ * @param {Entropy} entropy bytes (Uint8Array) or secret (bigint)
25
+ * @throws {SecretKeyError} If entropy is not provided, not a valid 32-byte secret key or not a valid bigint seed
26
+ */
27
+ constructor(entropy) {
28
+ // If entropy not valid bytes or bigint seed, throw an error
29
+ const isBytes = entropy instanceof Uint8Array;
30
+ const isSecret = typeof entropy === 'bigint';
31
+ if (!isBytes && !isSecret) {
32
+ throw new SecretKeyError('Invalid entropy: must be a valid byte array (32) or bigint', 'CONSTRUCTOR_ERROR');
33
+ }
34
+ // If bytes and bytes are not length 32
35
+ if (isBytes && entropy.length === 32) {
36
+ this._bytes = entropy;
37
+ this._seed = SecretKey.toSecret(entropy);
38
+ }
39
+ // If secret and secret is not a valid bigint, throw error
40
+ if (isSecret && !(entropy < 1n || entropy >= CURVE.n)) {
41
+ this._bytes = SecretKey.toBytes(entropy);
42
+ this._seed = entropy;
43
+ }
44
+ if (!this._bytes || this._bytes.length !== 32) {
45
+ throw new SecretKeyError('Invalid bytes: must be a valid 32-byte secret key', 'CONSTRUCTOR_ERROR');
46
+ }
47
+ if (!this._seed || (this._seed < 1n || this._seed >= CURVE.n)) {
48
+ throw new SecretKeyError('Invalid seed: must must be valid bigint', 'CONSTRUCTOR_ERROR');
49
+ }
50
+ // Set the secret key multibase
51
+ this._multibase = this.encode();
52
+ }
53
+ /**
54
+ * Get the secret key entropy as a byte array.
55
+ * @returns {KeyBytes} The secret key bytes as a Uint8Array
56
+ */
57
+ get bytes() {
58
+ // Return a copy of the secret key bytes
59
+ const bytes = new Uint8Array(this._bytes);
60
+ return bytes;
61
+ }
62
+ /**
63
+ * Get the secret key entropy as a bigint.
64
+ * @returns {bigint} The secret key as a bigint
65
+ */
66
+ get seed() {
67
+ // Memoize the secret and return
68
+ const seed = BigInt(this._seed);
69
+ return seed;
70
+ }
71
+ /**
72
+ * Returns the raw secret key as a hex string.
73
+ * @returns {Hex} The secret key as a hex string
74
+ */
75
+ get hex() {
76
+ // Convert the raw secret key bytes to a hex string
77
+ return Buffer.from(this.bytes).toString('hex');
78
+ }
79
+ /**
80
+ * Encode the secret key bytes as a secretKeyMultibase string.
81
+ * @returns {string} The secret key in base58btc multibase format
82
+ */
83
+ get multibase() {
84
+ const multibase = this._multibase;
85
+ return multibase;
86
+ }
87
+ /**
88
+ * Encodes the secret key bytes to BIP340 multibase format.
89
+ * @returns {string} The secret key in BIP340 multibase format.
90
+ */
91
+ encode() {
92
+ // Convert Uint8Array bytes to an Array
93
+ const secretKeyBytes = this.bytes.toArray();
94
+ if (secretKeyBytes.length !== 32) {
95
+ throw new SecretKeyError('Invalid secret key: must be a valid 32-byte secret key', 'ENCODE_MULTIBASE_ERROR');
96
+ }
97
+ // Convert prefix to an array
98
+ const mbaseBytes = BIP340_SECRET_KEY_MULTIBASE_PREFIX.toArray();
99
+ // Push the secret key bytes at the end of the prefix
100
+ mbaseBytes.push(...secretKeyBytes);
101
+ // Encode the bytes in base58btc format and return
102
+ return base58btc.encode(mbaseBytes.toUint8Array());
103
+ }
104
+ /**
105
+ * Checks if this secret key is equal to another.
106
+ * @param {SecretKey} other The other secret key
107
+ * @returns {boolean} True if the private keys are equal, false otherwise
108
+ */
109
+ equals(other) {
110
+ // Compare the hex strings of the private keys
111
+ return this.hex === other.hex;
112
+ }
113
+ /**
114
+ * Computes the public key from the secret key bytes.
115
+ * @returns {KeyBytes} The computed public key
116
+ */
117
+ computePublicKey() {
118
+ // Derive the public key from the secret key
119
+ const publicKeyBytes = tinysecp.pointFromScalar(this.bytes, true);
120
+ // If no public key, throw error
121
+ if (!publicKeyBytes) {
122
+ throw new SecretKeyError('Invalid compute: failed to derive public key', 'COMPUTE_PUBLIC_KEY_ERROR');
123
+ }
124
+ // If public key is not compressed, throw error
125
+ if (publicKeyBytes.length !== 33) {
126
+ throw new SecretKeyError('Invalid compute: public key not compressed format', 'COMPUTE_PUBLIC_KEY_ERROR');
127
+ }
128
+ return publicKeyBytes;
129
+ }
130
+ /**
131
+ * Converts the secret key to a JSON object.
132
+ * @returns {SecretKeyObject} The secret key as a JSON object
133
+ */
134
+ json() {
135
+ return {
136
+ bytes: this.bytes.toArray(),
137
+ seed: this.seed.toString(),
138
+ hex: this.hex,
139
+ };
140
+ }
141
+ /**
142
+ * Checks if the secret key is valid.
143
+ * @returns {boolean} True if the secret key is valid, false otherwise
144
+ */
145
+ isValid() {
146
+ return tinysecp.isPrivate(this.bytes);
147
+ }
148
+ /**
149
+ * Checks if the public key is a valid secp256k1 point.
150
+ * @param {PublicKey} pk The public key to validate
151
+ * @returns {boolean} True if the public key is valid, false otherwise
152
+ */
153
+ isValidPair(pk) {
154
+ // If the public key is not valid, return false
155
+ if (!tinysecp.isPoint(pk.compressed)) {
156
+ return false;
157
+ }
158
+ // Else return true
159
+ return true;
160
+ }
161
+ /**
162
+ * Decodes the multibase string to the 34-byte secret key (2 byte prefix + 32 byte key).
163
+ * @param {string} multibase The multibase string to decode
164
+ * @returns {Bytes} The decoded secret key.
165
+ */
166
+ static decode(multibase) {
167
+ // Decode the public key multibase string
168
+ const decoded = base58btc.decode(multibase);
169
+ // If the public key bytes are not 35 bytes, throw an error
170
+ if (decoded.length !== 34) {
171
+ throw new SecretKeyError('Invalid argument: must be 34 byte secretKeyMultibase', 'DECODE_MULTIBASE_ERROR');
172
+ }
173
+ // Grab the prefix bytes
174
+ const prefix = decoded.slice(0, 2);
175
+ // Compute the prefix hash
176
+ const prefixHash = Buffer.from(sha256(prefix)).toString('hex');
177
+ // If the prefix hash does not equal the BIP340 prefix hash, throw an error
178
+ if (prefixHash !== BIP340_SECRET_KEY_MULTIBASE_PREFIX_HASH) {
179
+ throw new SecretKeyError(`Invalid prefix: malformed multibase prefix ${prefix}`, 'DECODE_MULTIBASE_ERROR');
180
+ }
181
+ // Return the decoded key bytes
182
+ return decoded;
183
+ }
184
+ /**
185
+ * Creates a SecretKey object from a JSON object.
186
+ * @param {SecretKeyObject} json The JSON object containing the secret key bytes
187
+ * @returns {SecretKey} A new SecretKey object
188
+ */
189
+ static fromJSON(json) {
190
+ return new SecretKey(new Uint8Array(json.bytes));
191
+ }
192
+ /**
193
+ * Converts a SecretKey or KeyBytes to a Pair.
194
+ * @param {KeyBytes} bytes
195
+ * @returns {SchnorrKeyPair} The SchnorrKeyPair object containing the public and private keys
196
+ * @throws {SecretKeyError} If the secret key is not valid
197
+ */
198
+ static toKeyPair(bytes) {
199
+ // Create a new SecretKey from the bytes
200
+ const secretKey = new SecretKey(bytes);
201
+ // Compute the public key from the secret key
202
+ const publicKey = secretKey.computePublicKey();
203
+ // Create a new Pair from the public key and secret key
204
+ return new SchnorrKeyPair({ publicKey, secretKey });
205
+ }
206
+ /**
207
+ * Convert a bigint secret to secret key bytes.
208
+ * @param {KeyBytes} bytes The secret key bytes
209
+ * @returns {bigint} The secret key bytes as a bigint secret
210
+ */
211
+ static toSecret(bytes) {
212
+ return bytes.reduce((acc, byte) => (acc << 8n) | BigInt(byte), 0n);
213
+ }
214
+ /**
215
+ * Convert a secret key bytes to a bigint secret.
216
+ * @param {bigint} secret The secret key secret.
217
+ * @returns {KeyBytes} The secret key secret as secret key bytes.
218
+ */
219
+ static toBytes(secret) {
220
+ // Ensure it’s a valid 32-byte value in [1, n-1] and convert bigint to Uint8Array
221
+ const bytes = Uint8Array.from({ length: 32 }, (_, i) => Number(secret >> BigInt(8 * (31 - i)) & BigInt(0xff)));
222
+ // If bytes are not a valid secp256k1 secret key, throw error
223
+ if (!tinysecp.isPrivate(bytes)) {
224
+ throw new SecretKeyError('Invalid secret key: secret out of valid range', 'SET_PRIVATE_KEY_ERROR');
225
+ }
226
+ return new Uint8Array(bytes);
227
+ }
228
+ /**
229
+ * Creates a new SecretKey object from a bigint secret.
230
+ * @param {bigint} secret The secret bigint
231
+ * @returns {SecretKey} A new SecretKey object
232
+ */
233
+ static fromSecret(secret) {
234
+ // Convert the secret bigint to a hex string
235
+ const hexsecret = secret.toString(16).padStart(64, '0');
236
+ // Convert the hex string to a Uint8Array
237
+ const privateKeyBytes = new Uint8Array(hexsecret.match(/.{2}/g).map(byte => parseInt(byte, 16)));
238
+ // Return a new SecretKey object
239
+ return new SecretKey(privateKeyBytes);
240
+ }
241
+ /**
242
+ * Generates random secret key bytes.
243
+ * @returns {KeyBytes} Uint8Array of 32 random bytes.
244
+ */
245
+ static random() {
246
+ // Generate empty 32-byte array
247
+ const byteArray = new Uint8Array(32);
248
+ // Use the getRandomValues function to fill the byteArray with random values
249
+ return getRandomValues(byteArray);
250
+ }
251
+ /**
252
+ * Creates a new SecretKey from random secret key bytes.
253
+ * @returns {SecretKey} A new SecretKey object
254
+ */
255
+ static generate() {
256
+ // Generate empty 32-byte array
257
+ const randomBytes = this.random();
258
+ // Use the getRandomValues function to fill the byteArray with random values
259
+ return new SecretKey(randomBytes);
260
+ }
261
+ /**
262
+ * Generates a public key from the given secret key bytes.
263
+ * @param {KeyBytes} bytes The secret key bytes
264
+ * @returns {KeyBytes} The computed public key bytes
265
+ */
266
+ static getPublicKey(bytes) {
267
+ // Create a new SecretKey from the bytes and compute the public key
268
+ return new SecretKey(bytes).computePublicKey();
269
+ }
270
+ }
271
+ //# sourceMappingURL=secret.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secret.js","sourceRoot":"","sources":["../../src/secret.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,EAClC,uCAAuC,EAEvC,KAAK,EAIL,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAuD3C;;;;;;;GAOG;AACH,MAAM,OAAO,SAAS;IACpB,sEAAsE;IAC9D,MAAM,CAAY;IAE1B,gEAAgE;IACxD,KAAK,CAAU;IAEvB,4DAA4D;IACpD,UAAU,CAAS;IAE3B;;;;OAIG;IACH,YAAY,OAAgB;QAC1B,4DAA4D;QAC5D,MAAM,OAAO,GAAG,OAAO,YAAY,UAAU,CAAC;QAC9C,MAAM,QAAQ,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC;QAC7C,IAAG,CAAC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;YACzB,MAAM,IAAI,cAAc,CACtB,4DAA4D,EAC5D,mBAAmB,CACpB,CAAC;QACJ,CAAC;QAED,uCAAuC;QACvC,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACrC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;YACtB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CA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C,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QACxD,yCAAyC;QACzC,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QAClG,gCAAgC;QAChC,OAAO,IAAI,SAAS,CAAC,eAAe,CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,MAAM;QAClB,+BAA+B;QAC/B,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;QAErC,4EAA4E;QAC5E,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAGD;;;OAGG;IACI,MAAM,CAAC,QAAQ;QACpB,+BAA+B;QAC/B,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAElC,4EAA4E;QAC5E,OAAO,IAAI,SAAS,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,YAAY,CAAC,KAAe;QACxC,mEAAmE;QACnE,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACjD,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export * from './pair.js';
2
+ export * from './secret.js';
3
+ export * from './public.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}