@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.
- package/LICENSE +373 -0
- package/README.md +4 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pair.js +203 -0
- package/dist/cjs/pair.js.map +1 -0
- package/dist/cjs/public.js +283 -0
- package/dist/cjs/public.js.map +1 -0
- package/dist/cjs/secret.js +271 -0
- package/dist/cjs/secret.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/pair.js +203 -0
- package/dist/esm/pair.js.map +1 -0
- package/dist/esm/public.js +283 -0
- package/dist/esm/public.js.map +1 -0
- package/dist/esm/secret.js +271 -0
- package/dist/esm/secret.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/pair.d.ts +126 -0
- package/dist/types/pair.d.ts.map +1 -0
- package/dist/types/public.d.ts +197 -0
- package/dist/types/public.d.ts.map +1 -0
- package/dist/types/secret.d.ts +174 -0
- package/dist/types/secret.d.ts.map +1 -0
- package/package.json +120 -0
- package/src/index.ts +3 -0
- package/src/pair.ts +274 -0
- package/src/public.ts +424 -0
- package/src/secret.ts +410 -0
package/dist/esm/pair.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { KeyPairError } from '@did-btcr2/common';
|
|
2
|
+
import { PublicKey } from './public.js';
|
|
3
|
+
import { SecretKey } from './secret.js';
|
|
4
|
+
/**
|
|
5
|
+
* Encapsulates a PublicKey and a SecretKey object as a single Keys object.
|
|
6
|
+
* @class SchnorrKeyPair
|
|
7
|
+
* @type {SchnorrKeyPair}
|
|
8
|
+
*/
|
|
9
|
+
export class SchnorrKeyPair {
|
|
10
|
+
/** @type {SecretKey} The secret key object */
|
|
11
|
+
_secretKey;
|
|
12
|
+
/** @type {PublicKey} The public key object */ ;
|
|
13
|
+
_publicKey;
|
|
14
|
+
/** @type {string} The public key in multibase format */
|
|
15
|
+
_publicKeyMultibase;
|
|
16
|
+
/** @type {string} The secret key in multibase format */
|
|
17
|
+
_secretKeyMultibase;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of Keys. Must provide a at least a secret key.
|
|
20
|
+
* Can optionally provide both a private and public key, but must be a valid pair.
|
|
21
|
+
* @param {SecretKey} secretKey The secret key object
|
|
22
|
+
*/
|
|
23
|
+
constructor({ secretKey, publicKey } = {}) {
|
|
24
|
+
// If no secret key or public key, throw an error
|
|
25
|
+
if (!publicKey && !secretKey) {
|
|
26
|
+
throw new KeyPairError('Argument missing: must at least provide a publicKey', 'CONSTRUCTOR_ERROR');
|
|
27
|
+
}
|
|
28
|
+
// Set the secret key
|
|
29
|
+
if (secretKey instanceof Uint8Array) {
|
|
30
|
+
this._secretKey = new SecretKey(secretKey);
|
|
31
|
+
}
|
|
32
|
+
else if (secretKey instanceof SecretKey) {
|
|
33
|
+
this._secretKey = secretKey;
|
|
34
|
+
}
|
|
35
|
+
// Set the public key
|
|
36
|
+
if (publicKey instanceof PublicKey) {
|
|
37
|
+
this._publicKey = publicKey;
|
|
38
|
+
}
|
|
39
|
+
else if (publicKey instanceof Uint8Array) {
|
|
40
|
+
this._publicKey = new PublicKey(publicKey);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this._publicKey = new PublicKey(this._secretKey.computePublicKey());
|
|
44
|
+
}
|
|
45
|
+
this._publicKeyMultibase = this._publicKey.multibase.address;
|
|
46
|
+
this._secretKeyMultibase = this._secretKey ? this._secretKey.multibase : '';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get the SecretKey.
|
|
50
|
+
* @returns {SecretKey} The SecretKey object
|
|
51
|
+
* @throws {KeyPairError} If the secret key is not available
|
|
52
|
+
*/
|
|
53
|
+
get secretKey() {
|
|
54
|
+
// If the secret key is not available, throw an error
|
|
55
|
+
if (!this._secretKey) {
|
|
56
|
+
throw new KeyPairError('Secret key not available', 'SECRET_KEY_ERROR');
|
|
57
|
+
}
|
|
58
|
+
// If the secret key is not valid, throw an error
|
|
59
|
+
if (!this._secretKey.isValid()) {
|
|
60
|
+
throw new KeyPairError('Secret key is not valid', 'SECRET_KEY_ERROR');
|
|
61
|
+
}
|
|
62
|
+
// Return a copy of the secret key
|
|
63
|
+
const secretKey = this._secretKey;
|
|
64
|
+
return secretKey;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Set the PublicKey.
|
|
68
|
+
* @param {PublicKey} publicKey The PublicKey object
|
|
69
|
+
* @throws {KeyPairError} If the public key is not a valid pair with the secret key.
|
|
70
|
+
*/
|
|
71
|
+
set publicKey(publicKey) {
|
|
72
|
+
// If the public key is not a valid pair with the secret key, throw an error
|
|
73
|
+
if (this.secretKey && !this.secretKey.isValidPair(publicKey)) {
|
|
74
|
+
throw new KeyPairError('Public key is not a valid pair with the secret key', 'PUBLIC_KEY_ERROR');
|
|
75
|
+
}
|
|
76
|
+
this._publicKey = publicKey;
|
|
77
|
+
this._publicKeyMultibase = publicKey.multibase.address;
|
|
78
|
+
this._secretKeyMultibase = this._secretKey ? this._secretKey.multibase : '';
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get the PublicKey.
|
|
82
|
+
* @returns {PublicKey} The PublicKey object
|
|
83
|
+
*/
|
|
84
|
+
get publicKey() {
|
|
85
|
+
const publicKey = this._publicKey;
|
|
86
|
+
return publicKey;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the Keys as a raw key pair.
|
|
90
|
+
* @returns {RawKeyPair} The Keys as a raw key pair
|
|
91
|
+
*/
|
|
92
|
+
get raw() {
|
|
93
|
+
return {
|
|
94
|
+
public: this.publicKey.x,
|
|
95
|
+
secret: this.secretKey ? this.secretKey.bytes : undefined
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the Keys in multibase format.
|
|
100
|
+
* @returns {MultibaseKeys} The SecretKey in multibase format
|
|
101
|
+
*/
|
|
102
|
+
get multibase() {
|
|
103
|
+
return {
|
|
104
|
+
publicKeyMultibase: this._publicKeyMultibase,
|
|
105
|
+
secretKeyMultibase: this._secretKeyMultibase,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* JSON representation of a Keys.
|
|
110
|
+
* @returns {SchnorrKeyPairObject} The Keys as a JSON object
|
|
111
|
+
*/
|
|
112
|
+
json() {
|
|
113
|
+
return {
|
|
114
|
+
secretKey: this.secretKey.json(),
|
|
115
|
+
publicKey: this.publicKey.json()
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Static method creates a new Keys from a JSON object.
|
|
120
|
+
* @param {SchnorrKeyPairObject} keys The JSON object to initialize the Keys.
|
|
121
|
+
* @returns {SchnorrKeyPair} The initialized Keys object.
|
|
122
|
+
*/
|
|
123
|
+
static fromJSON(keys) {
|
|
124
|
+
const secretKey = SecretKey.fromJSON(keys.secretKey);
|
|
125
|
+
const publicKey = PublicKey.fromJSON(keys.publicKey);
|
|
126
|
+
return new SchnorrKeyPair({ secretKey, publicKey });
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Static method creates a new SchnorrKeyPair from a SecretKey object or secret key bytes.
|
|
130
|
+
* @param {SecretKey | KeyBytes} data The secret key bytes
|
|
131
|
+
* @returns {SchnorrKeyPair} A new SchnorrKeyPair object
|
|
132
|
+
*/
|
|
133
|
+
static fromPrivateKey(data) {
|
|
134
|
+
// If the secret key is a SecretKey object, get the raw bytes else use the bytes
|
|
135
|
+
const bytes = data instanceof SecretKey ? data.bytes : data;
|
|
136
|
+
// Throw error if the secret key is not 32 bytes
|
|
137
|
+
if (bytes.length !== 32) {
|
|
138
|
+
throw new KeyPairError('Invalid arg: must be 32 byte secret key', 'FROM_PRIVATE_KEY_ERROR');
|
|
139
|
+
}
|
|
140
|
+
// If pk Uint8Array, construct SecretKey object else use the object
|
|
141
|
+
const secretKey = data instanceof Uint8Array ? new SecretKey(data) : data;
|
|
142
|
+
// Compute the public key from the secret key
|
|
143
|
+
const publicKey = secretKey.computePublicKey();
|
|
144
|
+
// Return a new Keys object
|
|
145
|
+
return new SchnorrKeyPair({ secretKey, publicKey });
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Static method creates a new Keys (SecretKey/PublicKey) bigint secret.
|
|
149
|
+
* @param {bigint} secret The secret key secret
|
|
150
|
+
* @returns {Keys} A new Keys object
|
|
151
|
+
*/
|
|
152
|
+
static fromSecret(secret) {
|
|
153
|
+
const secretKey = SecretKey.fromSecret(secret);
|
|
154
|
+
const publicKey = secretKey.computePublicKey();
|
|
155
|
+
return new SchnorrKeyPair({ secretKey, publicKey });
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Converts key bytes to a hex string.
|
|
159
|
+
* @param {KeyBytes} keyBytes The key bytes (private or public).
|
|
160
|
+
* @returns {Hex} The key bytes as a hex string.
|
|
161
|
+
*/
|
|
162
|
+
static toHex(keyBytes) {
|
|
163
|
+
return Buffer.from(keyBytes).toString('hex');
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Compares two Keys objects for equality.
|
|
167
|
+
* @param {SchnorrKeyPair} keys The main keys.
|
|
168
|
+
* @param {SchnorrKeyPair} otherKeys The other keys to compare.
|
|
169
|
+
* @returns {boolean} True if the public key and secret key are equal, false otherwise.
|
|
170
|
+
*/
|
|
171
|
+
static equals(keys, otherKeys) {
|
|
172
|
+
// Deconstruct the public keys from the key pairs
|
|
173
|
+
const pk = keys.publicKey;
|
|
174
|
+
const otherPk = otherKeys.publicKey;
|
|
175
|
+
// If publicKeys present, use to compare as hex strings.
|
|
176
|
+
if (pk && otherPk) {
|
|
177
|
+
return pk.hex === otherPk.hex;
|
|
178
|
+
}
|
|
179
|
+
// Deconstruct the private keys from the key pairs
|
|
180
|
+
const sk = keys.secretKey;
|
|
181
|
+
const otherSk = otherKeys.secretKey;
|
|
182
|
+
if (sk && otherSk) {
|
|
183
|
+
// Get the public key hex strings for both key pair publicKeys
|
|
184
|
+
return sk.hex === otherSk.hex;
|
|
185
|
+
}
|
|
186
|
+
throw new KeyPairError('Cannot compare invalid key pair(s)', 'KEYPAIR_EQUALS_ERROR');
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Static method to generate a new random SchnorrKeyPair instance.
|
|
190
|
+
* @returns {SchnorrKeyPair} A new SecretKey object.
|
|
191
|
+
*/
|
|
192
|
+
static generate() {
|
|
193
|
+
// Generate random secret key bytes
|
|
194
|
+
const skBytes = SecretKey.random();
|
|
195
|
+
// Construct a new SecretKey object
|
|
196
|
+
const secretKey = new SecretKey(skBytes);
|
|
197
|
+
// Compute the public key from the secret key
|
|
198
|
+
const publicKey = secretKey.computePublicKey();
|
|
199
|
+
// Return a new Keys object
|
|
200
|
+
return new SchnorrKeyPair({ secretKey, publicKey });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=pair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pair.js","sourceRoot":"","sources":["../../src/pair.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAEb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAyCxC;;;;GAIG;AACH,MAAM,OAAO,cAAc;IACzB,8CAA8C;IACtC,UAAU,CAAa;IAE/B,8CAA8C,CAAA,CAAC;IACvC,UAAU,CAAY;IAE9B,wDAAwD;IAChD,mBAAmB,CAAS;IAEpC,wDAAwD;IAChD,mBAAmB,CAAS;IAEpC;;;;OAIG;IACH,YAAY,EAAE,SAAS,EAAE,SAAS,KAAgB,EAAE;QAClD,iDAAiD;QACjD,IAAI,CAAC,SAAS,IAAI,CAAC,SA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@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,CA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