@leofcoin/chain 1.5.64 → 1.5.66
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/exports/browser/{browser-1GyRaZxg-C9SpI6hG.js → browser-Ei0BXMlu-irDJ6Blw.js} +1 -1
- package/exports/browser/browser-store.js +40 -308
- package/exports/browser/chain.js +5 -1
- package/exports/browser/{client-UOCjJBGl-pbv-pTHd.js → client-A009z8av-uBa1w1TW.js} +3 -3
- package/exports/browser/{index-ub31QSed-EMPr2oeb.js → index-G74WLzL7-tmiSHjUc.js} +1 -1
- package/exports/browser/{index-K4Kwju30-vS3fNpxy.js → index-YQrIDBUQ-OXiMI4eT.js} +1 -1
- package/exports/browser/{messages-guyZfse6-JeAlT5Nb.js → messages-lWRTai7t-Bc6ghkkt.js} +1 -1
- package/exports/browser/{node-browser-0Ly80awM.js → node-browser-TcXF8FDB.js} +621 -619
- package/exports/browser/node-browser.js +1 -1
- package/exports/chain.js +3 -0
- package/package.json +1 -1
|
@@ -107,7 +107,8 @@ const debug$1 = (target, text) => {
|
|
|
107
107
|
globalThis.DEBUG === 'true' ||
|
|
108
108
|
globalThis.DEBUG === true ||
|
|
109
109
|
globalThis.DEBUG?.indexOf(target) !== -1 ||
|
|
110
|
-
globalThis.DEBUG?.indexOf('*') !== -1
|
|
110
|
+
globalThis.DEBUG?.indexOf('*') !== -1 ||
|
|
111
|
+
globalThis.DEBUG?.indexOf(target.split('/')[0]) !== -1
|
|
111
112
|
)
|
|
112
113
|
if (text) console.log('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
|
|
113
114
|
else console.log('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
|
|
@@ -12858,6 +12859,7 @@ const nothingFoundError = (hash) => {
|
|
|
12858
12859
|
};
|
|
12859
12860
|
|
|
12860
12861
|
const isBrowser = globalThis.process?.versions?.node ? false : true;
|
|
12862
|
+
|
|
12861
12863
|
let LeofcoinStorage$1 = class LeofcoinStorage {
|
|
12862
12864
|
name;
|
|
12863
12865
|
root;
|
|
@@ -12893,7 +12895,7 @@ let LeofcoinStorage$1 = class LeofcoinStorage {
|
|
|
12893
12895
|
if (typeof key === 'object')
|
|
12894
12896
|
return this.many('has', key);
|
|
12895
12897
|
try {
|
|
12896
|
-
const has = await this.db.
|
|
12898
|
+
const has = await this.db.has(new KeyPath(key));
|
|
12897
12899
|
return Boolean(has);
|
|
12898
12900
|
}
|
|
12899
12901
|
catch (e) {
|
|
@@ -13106,185 +13108,522 @@ var index$1 = {
|
|
|
13106
13108
|
}
|
|
13107
13109
|
};
|
|
13108
13110
|
|
|
13109
|
-
|
|
13110
|
-
|
|
13111
|
-
|
|
13112
|
-
|
|
13113
|
-
|
|
13114
|
-
|
|
13115
|
-
|
|
13116
|
-
|
|
13117
|
-
|
|
13118
|
-
|
|
13119
|
-
|
|
13120
|
-
|
|
13121
|
-
|
|
13122
|
-
|
|
13123
|
-
version: "grunt dist && git add dist/"
|
|
13124
|
-
};
|
|
13125
|
-
var repository = {
|
|
13126
|
-
type: "git",
|
|
13127
|
-
url: "git@github.com:indutny/elliptic"
|
|
13128
|
-
};
|
|
13129
|
-
var keywords = [
|
|
13130
|
-
"EC",
|
|
13131
|
-
"Elliptic",
|
|
13132
|
-
"curve",
|
|
13133
|
-
"Cryptography"
|
|
13134
|
-
];
|
|
13135
|
-
var author = "Fedor Indutny <fedor@indutny.com>";
|
|
13136
|
-
var license = "MIT";
|
|
13137
|
-
var bugs = {
|
|
13138
|
-
url: "https://github.com/indutny/elliptic/issues"
|
|
13139
|
-
};
|
|
13140
|
-
var homepage = "https://github.com/indutny/elliptic";
|
|
13141
|
-
var devDependencies = {
|
|
13142
|
-
brfs: "^2.0.2",
|
|
13143
|
-
coveralls: "^3.1.0",
|
|
13144
|
-
eslint: "^7.6.0",
|
|
13145
|
-
grunt: "^1.2.1",
|
|
13146
|
-
"grunt-browserify": "^5.3.0",
|
|
13147
|
-
"grunt-cli": "^1.3.2",
|
|
13148
|
-
"grunt-contrib-connect": "^3.0.0",
|
|
13149
|
-
"grunt-contrib-copy": "^1.0.0",
|
|
13150
|
-
"grunt-contrib-uglify": "^5.0.0",
|
|
13151
|
-
"grunt-mocha-istanbul": "^5.0.2",
|
|
13152
|
-
"grunt-saucelabs": "^9.0.1",
|
|
13153
|
-
istanbul: "^0.4.5",
|
|
13154
|
-
mocha: "^8.0.1"
|
|
13155
|
-
};
|
|
13156
|
-
var dependencies = {
|
|
13157
|
-
"bn.js": "^4.11.9",
|
|
13158
|
-
brorand: "^1.1.0",
|
|
13159
|
-
"hash.js": "^1.0.0",
|
|
13160
|
-
"hmac-drbg": "^1.0.1",
|
|
13161
|
-
inherits: "^2.0.4",
|
|
13162
|
-
"minimalistic-assert": "^1.0.1",
|
|
13163
|
-
"minimalistic-crypto-utils": "^1.0.1"
|
|
13164
|
-
};
|
|
13165
|
-
var require$$0 = {
|
|
13166
|
-
name: name,
|
|
13167
|
-
version: version$1,
|
|
13168
|
-
description: description,
|
|
13169
|
-
main: main,
|
|
13170
|
-
files: files,
|
|
13171
|
-
scripts: scripts,
|
|
13172
|
-
repository: repository,
|
|
13173
|
-
keywords: keywords,
|
|
13174
|
-
author: author,
|
|
13175
|
-
license: license,
|
|
13176
|
-
bugs: bugs,
|
|
13177
|
-
homepage: homepage,
|
|
13178
|
-
devDependencies: devDependencies,
|
|
13179
|
-
dependencies: dependencies
|
|
13111
|
+
const errors = {
|
|
13112
|
+
IMPOSSIBLE_CASE: 'Impossible case. Please create issue.',
|
|
13113
|
+
TWEAK_ADD:
|
|
13114
|
+
'The tweak was out of range or the resulted private key is invalid',
|
|
13115
|
+
TWEAK_MUL: 'The tweak was out of range or equal to zero',
|
|
13116
|
+
CONTEXT_RANDOMIZE_UNKNOW: 'Unknow error on context randomization',
|
|
13117
|
+
SECKEY_INVALID: 'Private Key is invalid',
|
|
13118
|
+
PUBKEY_PARSE: 'Public Key could not be parsed',
|
|
13119
|
+
PUBKEY_SERIALIZE: 'Public Key serialization error',
|
|
13120
|
+
PUBKEY_COMBINE: 'The sum of the public keys is not valid',
|
|
13121
|
+
SIG_PARSE: 'Signature could not be parsed',
|
|
13122
|
+
SIGN: 'The nonce generation function failed, or the private key was invalid',
|
|
13123
|
+
RECOVER: 'Public key could not be recover',
|
|
13124
|
+
ECDH: 'Scalar was invalid (zero or overflow)'
|
|
13180
13125
|
};
|
|
13181
13126
|
|
|
13182
|
-
|
|
13183
|
-
|
|
13184
|
-
|
|
13127
|
+
function assert$g (cond, msg) {
|
|
13128
|
+
if (!cond) throw new Error(msg)
|
|
13129
|
+
}
|
|
13185
13130
|
|
|
13186
|
-
|
|
13187
|
-
|
|
13131
|
+
function isUint8Array (name, value, length) {
|
|
13132
|
+
assert$g(value instanceof Uint8Array, `Expected ${name} to be an Uint8Array`);
|
|
13188
13133
|
|
|
13189
|
-
|
|
13190
|
-
|
|
13191
|
-
|
|
13192
|
-
|
|
13134
|
+
if (length !== undefined) {
|
|
13135
|
+
if (Array.isArray(length)) {
|
|
13136
|
+
const numbers = length.join(', ');
|
|
13137
|
+
const msg = `Expected ${name} to be an Uint8Array with length [${numbers}]`;
|
|
13138
|
+
assert$g(length.includes(value.length), msg);
|
|
13139
|
+
} else {
|
|
13140
|
+
const msg = `Expected ${name} to be an Uint8Array with length ${length}`;
|
|
13141
|
+
assert$g(value.length === length, msg);
|
|
13142
|
+
}
|
|
13143
|
+
}
|
|
13144
|
+
}
|
|
13193
13145
|
|
|
13194
|
-
|
|
13195
|
-
|
|
13196
|
-
|
|
13197
|
-
ctor.super_ = superCtor;
|
|
13198
|
-
var TempCtor = function () {};
|
|
13199
|
-
TempCtor.prototype = superCtor.prototype;
|
|
13200
|
-
ctor.prototype = new TempCtor();
|
|
13201
|
-
ctor.prototype.constructor = ctor;
|
|
13202
|
-
}
|
|
13146
|
+
function isCompressed (value) {
|
|
13147
|
+
assert$g(toTypeString(value) === 'Boolean', 'Expected compressed to be a Boolean');
|
|
13148
|
+
}
|
|
13203
13149
|
|
|
13204
|
-
|
|
13150
|
+
function getAssertedOutput (output = (len) => new Uint8Array(len), length) {
|
|
13151
|
+
if (typeof output === 'function') output = output(length);
|
|
13152
|
+
isUint8Array('output', output, length);
|
|
13153
|
+
return output
|
|
13154
|
+
}
|
|
13205
13155
|
|
|
13206
|
-
|
|
13207
|
-
|
|
13208
|
-
|
|
13209
|
-
}
|
|
13156
|
+
function toTypeString (value) {
|
|
13157
|
+
return Object.prototype.toString.call(value).slice(8, -1)
|
|
13158
|
+
}
|
|
13210
13159
|
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
|
|
13160
|
+
var lib = (secp256k1) => {
|
|
13161
|
+
return {
|
|
13162
|
+
contextRandomize (seed) {
|
|
13163
|
+
assert$g(
|
|
13164
|
+
seed === null || seed instanceof Uint8Array,
|
|
13165
|
+
'Expected seed to be an Uint8Array or null'
|
|
13166
|
+
);
|
|
13167
|
+
if (seed !== null) isUint8Array('seed', seed, 32);
|
|
13214
13168
|
|
|
13215
|
-
|
|
13216
|
-
|
|
13169
|
+
switch (secp256k1.contextRandomize(seed)) {
|
|
13170
|
+
case 1:
|
|
13171
|
+
throw new Error(errors.CONTEXT_RANDOMIZE_UNKNOW)
|
|
13172
|
+
}
|
|
13173
|
+
},
|
|
13217
13174
|
|
|
13218
|
-
|
|
13219
|
-
|
|
13220
|
-
endian = base;
|
|
13221
|
-
base = 10;
|
|
13222
|
-
}
|
|
13175
|
+
privateKeyVerify (seckey) {
|
|
13176
|
+
isUint8Array('private key', seckey, 32);
|
|
13223
13177
|
|
|
13224
|
-
|
|
13225
|
-
|
|
13226
|
-
}
|
|
13227
|
-
if (typeof module === 'object') {
|
|
13228
|
-
module.exports = BN;
|
|
13229
|
-
} else {
|
|
13230
|
-
exports.BN = BN;
|
|
13231
|
-
}
|
|
13178
|
+
return secp256k1.privateKeyVerify(seckey) === 0
|
|
13179
|
+
},
|
|
13232
13180
|
|
|
13233
|
-
|
|
13234
|
-
|
|
13181
|
+
privateKeyNegate (seckey) {
|
|
13182
|
+
isUint8Array('private key', seckey, 32);
|
|
13235
13183
|
|
|
13236
|
-
|
|
13237
|
-
|
|
13238
|
-
|
|
13239
|
-
|
|
13240
|
-
|
|
13241
|
-
|
|
13242
|
-
|
|
13243
|
-
} catch (e) {
|
|
13244
|
-
}
|
|
13184
|
+
switch (secp256k1.privateKeyNegate(seckey)) {
|
|
13185
|
+
case 0:
|
|
13186
|
+
return seckey
|
|
13187
|
+
case 1:
|
|
13188
|
+
throw new Error(errors.IMPOSSIBLE_CASE)
|
|
13189
|
+
}
|
|
13190
|
+
},
|
|
13245
13191
|
|
|
13246
|
-
|
|
13247
|
-
|
|
13248
|
-
|
|
13249
|
-
}
|
|
13192
|
+
privateKeyTweakAdd (seckey, tweak) {
|
|
13193
|
+
isUint8Array('private key', seckey, 32);
|
|
13194
|
+
isUint8Array('tweak', tweak, 32);
|
|
13250
13195
|
|
|
13251
|
-
|
|
13252
|
-
|
|
13253
|
-
|
|
13196
|
+
switch (secp256k1.privateKeyTweakAdd(seckey, tweak)) {
|
|
13197
|
+
case 0:
|
|
13198
|
+
return seckey
|
|
13199
|
+
case 1:
|
|
13200
|
+
throw new Error(errors.TWEAK_ADD)
|
|
13201
|
+
}
|
|
13202
|
+
},
|
|
13254
13203
|
|
|
13255
|
-
|
|
13256
|
-
|
|
13257
|
-
|
|
13258
|
-
};
|
|
13204
|
+
privateKeyTweakMul (seckey, tweak) {
|
|
13205
|
+
isUint8Array('private key', seckey, 32);
|
|
13206
|
+
isUint8Array('tweak', tweak, 32);
|
|
13259
13207
|
|
|
13260
|
-
|
|
13261
|
-
|
|
13262
|
-
|
|
13263
|
-
|
|
13208
|
+
switch (secp256k1.privateKeyTweakMul(seckey, tweak)) {
|
|
13209
|
+
case 0:
|
|
13210
|
+
return seckey
|
|
13211
|
+
case 1:
|
|
13212
|
+
throw new Error(errors.TWEAK_MUL)
|
|
13213
|
+
}
|
|
13214
|
+
},
|
|
13264
13215
|
|
|
13265
|
-
|
|
13266
|
-
|
|
13267
|
-
return this._initNumber(number, base, endian);
|
|
13268
|
-
}
|
|
13216
|
+
publicKeyVerify (pubkey) {
|
|
13217
|
+
isUint8Array('public key', pubkey, [33, 65]);
|
|
13269
13218
|
|
|
13270
|
-
|
|
13271
|
-
|
|
13272
|
-
}
|
|
13219
|
+
return secp256k1.publicKeyVerify(pubkey) === 0
|
|
13220
|
+
},
|
|
13273
13221
|
|
|
13274
|
-
|
|
13275
|
-
|
|
13276
|
-
|
|
13277
|
-
|
|
13222
|
+
publicKeyCreate (seckey, compressed = true, output) {
|
|
13223
|
+
isUint8Array('private key', seckey, 32);
|
|
13224
|
+
isCompressed(compressed);
|
|
13225
|
+
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
13278
13226
|
|
|
13279
|
-
|
|
13280
|
-
|
|
13281
|
-
|
|
13282
|
-
|
|
13283
|
-
|
|
13284
|
-
|
|
13227
|
+
switch (secp256k1.publicKeyCreate(output, seckey)) {
|
|
13228
|
+
case 0:
|
|
13229
|
+
return output
|
|
13230
|
+
case 1:
|
|
13231
|
+
throw new Error(errors.SECKEY_INVALID)
|
|
13232
|
+
case 2:
|
|
13233
|
+
throw new Error(errors.PUBKEY_SERIALIZE)
|
|
13234
|
+
}
|
|
13235
|
+
},
|
|
13285
13236
|
|
|
13286
|
-
|
|
13287
|
-
|
|
13237
|
+
publicKeyConvert (pubkey, compressed = true, output) {
|
|
13238
|
+
isUint8Array('public key', pubkey, [33, 65]);
|
|
13239
|
+
isCompressed(compressed);
|
|
13240
|
+
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
13241
|
+
|
|
13242
|
+
switch (secp256k1.publicKeyConvert(output, pubkey)) {
|
|
13243
|
+
case 0:
|
|
13244
|
+
return output
|
|
13245
|
+
case 1:
|
|
13246
|
+
throw new Error(errors.PUBKEY_PARSE)
|
|
13247
|
+
case 2:
|
|
13248
|
+
throw new Error(errors.PUBKEY_SERIALIZE)
|
|
13249
|
+
}
|
|
13250
|
+
},
|
|
13251
|
+
|
|
13252
|
+
publicKeyNegate (pubkey, compressed = true, output) {
|
|
13253
|
+
isUint8Array('public key', pubkey, [33, 65]);
|
|
13254
|
+
isCompressed(compressed);
|
|
13255
|
+
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
13256
|
+
|
|
13257
|
+
switch (secp256k1.publicKeyNegate(output, pubkey)) {
|
|
13258
|
+
case 0:
|
|
13259
|
+
return output
|
|
13260
|
+
case 1:
|
|
13261
|
+
throw new Error(errors.PUBKEY_PARSE)
|
|
13262
|
+
case 2:
|
|
13263
|
+
throw new Error(errors.IMPOSSIBLE_CASE)
|
|
13264
|
+
case 3:
|
|
13265
|
+
throw new Error(errors.PUBKEY_SERIALIZE)
|
|
13266
|
+
}
|
|
13267
|
+
},
|
|
13268
|
+
|
|
13269
|
+
publicKeyCombine (pubkeys, compressed = true, output) {
|
|
13270
|
+
assert$g(Array.isArray(pubkeys), 'Expected public keys to be an Array');
|
|
13271
|
+
assert$g(pubkeys.length > 0, 'Expected public keys array will have more than zero items');
|
|
13272
|
+
for (const pubkey of pubkeys) {
|
|
13273
|
+
isUint8Array('public key', pubkey, [33, 65]);
|
|
13274
|
+
}
|
|
13275
|
+
isCompressed(compressed);
|
|
13276
|
+
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
13277
|
+
|
|
13278
|
+
switch (secp256k1.publicKeyCombine(output, pubkeys)) {
|
|
13279
|
+
case 0:
|
|
13280
|
+
return output
|
|
13281
|
+
case 1:
|
|
13282
|
+
throw new Error(errors.PUBKEY_PARSE)
|
|
13283
|
+
case 2:
|
|
13284
|
+
throw new Error(errors.PUBKEY_COMBINE)
|
|
13285
|
+
case 3:
|
|
13286
|
+
throw new Error(errors.PUBKEY_SERIALIZE)
|
|
13287
|
+
}
|
|
13288
|
+
},
|
|
13289
|
+
|
|
13290
|
+
publicKeyTweakAdd (pubkey, tweak, compressed = true, output) {
|
|
13291
|
+
isUint8Array('public key', pubkey, [33, 65]);
|
|
13292
|
+
isUint8Array('tweak', tweak, 32);
|
|
13293
|
+
isCompressed(compressed);
|
|
13294
|
+
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
13295
|
+
|
|
13296
|
+
switch (secp256k1.publicKeyTweakAdd(output, pubkey, tweak)) {
|
|
13297
|
+
case 0:
|
|
13298
|
+
return output
|
|
13299
|
+
case 1:
|
|
13300
|
+
throw new Error(errors.PUBKEY_PARSE)
|
|
13301
|
+
case 2:
|
|
13302
|
+
throw new Error(errors.TWEAK_ADD)
|
|
13303
|
+
}
|
|
13304
|
+
},
|
|
13305
|
+
|
|
13306
|
+
publicKeyTweakMul (pubkey, tweak, compressed = true, output) {
|
|
13307
|
+
isUint8Array('public key', pubkey, [33, 65]);
|
|
13308
|
+
isUint8Array('tweak', tweak, 32);
|
|
13309
|
+
isCompressed(compressed);
|
|
13310
|
+
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
13311
|
+
|
|
13312
|
+
switch (secp256k1.publicKeyTweakMul(output, pubkey, tweak)) {
|
|
13313
|
+
case 0:
|
|
13314
|
+
return output
|
|
13315
|
+
case 1:
|
|
13316
|
+
throw new Error(errors.PUBKEY_PARSE)
|
|
13317
|
+
case 2:
|
|
13318
|
+
throw new Error(errors.TWEAK_MUL)
|
|
13319
|
+
}
|
|
13320
|
+
},
|
|
13321
|
+
|
|
13322
|
+
signatureNormalize (sig) {
|
|
13323
|
+
isUint8Array('signature', sig, 64);
|
|
13324
|
+
|
|
13325
|
+
switch (secp256k1.signatureNormalize(sig)) {
|
|
13326
|
+
case 0:
|
|
13327
|
+
return sig
|
|
13328
|
+
case 1:
|
|
13329
|
+
throw new Error(errors.SIG_PARSE)
|
|
13330
|
+
}
|
|
13331
|
+
},
|
|
13332
|
+
|
|
13333
|
+
signatureExport (sig, output) {
|
|
13334
|
+
isUint8Array('signature', sig, 64);
|
|
13335
|
+
output = getAssertedOutput(output, 72);
|
|
13336
|
+
|
|
13337
|
+
const obj = { output, outputlen: 72 };
|
|
13338
|
+
switch (secp256k1.signatureExport(obj, sig)) {
|
|
13339
|
+
case 0:
|
|
13340
|
+
return output.slice(0, obj.outputlen)
|
|
13341
|
+
case 1:
|
|
13342
|
+
throw new Error(errors.SIG_PARSE)
|
|
13343
|
+
case 2:
|
|
13344
|
+
throw new Error(errors.IMPOSSIBLE_CASE)
|
|
13345
|
+
}
|
|
13346
|
+
},
|
|
13347
|
+
|
|
13348
|
+
signatureImport (sig, output) {
|
|
13349
|
+
isUint8Array('signature', sig);
|
|
13350
|
+
output = getAssertedOutput(output, 64);
|
|
13351
|
+
|
|
13352
|
+
switch (secp256k1.signatureImport(output, sig)) {
|
|
13353
|
+
case 0:
|
|
13354
|
+
return output
|
|
13355
|
+
case 1:
|
|
13356
|
+
throw new Error(errors.SIG_PARSE)
|
|
13357
|
+
case 2:
|
|
13358
|
+
throw new Error(errors.IMPOSSIBLE_CASE)
|
|
13359
|
+
}
|
|
13360
|
+
},
|
|
13361
|
+
|
|
13362
|
+
ecdsaSign (msg32, seckey, options = {}, output) {
|
|
13363
|
+
isUint8Array('message', msg32, 32);
|
|
13364
|
+
isUint8Array('private key', seckey, 32);
|
|
13365
|
+
assert$g(toTypeString(options) === 'Object', 'Expected options to be an Object');
|
|
13366
|
+
if (options.data !== undefined) isUint8Array('options.data', options.data);
|
|
13367
|
+
if (options.noncefn !== undefined) assert$g(toTypeString(options.noncefn) === 'Function', 'Expected options.noncefn to be a Function');
|
|
13368
|
+
output = getAssertedOutput(output, 64);
|
|
13369
|
+
|
|
13370
|
+
const obj = { signature: output, recid: null };
|
|
13371
|
+
switch (secp256k1.ecdsaSign(obj, msg32, seckey, options.data, options.noncefn)) {
|
|
13372
|
+
case 0:
|
|
13373
|
+
return obj
|
|
13374
|
+
case 1:
|
|
13375
|
+
throw new Error(errors.SIGN)
|
|
13376
|
+
case 2:
|
|
13377
|
+
throw new Error(errors.IMPOSSIBLE_CASE)
|
|
13378
|
+
}
|
|
13379
|
+
},
|
|
13380
|
+
|
|
13381
|
+
ecdsaVerify (sig, msg32, pubkey) {
|
|
13382
|
+
isUint8Array('signature', sig, 64);
|
|
13383
|
+
isUint8Array('message', msg32, 32);
|
|
13384
|
+
isUint8Array('public key', pubkey, [33, 65]);
|
|
13385
|
+
|
|
13386
|
+
switch (secp256k1.ecdsaVerify(sig, msg32, pubkey)) {
|
|
13387
|
+
case 0:
|
|
13388
|
+
return true
|
|
13389
|
+
case 3:
|
|
13390
|
+
return false
|
|
13391
|
+
case 1:
|
|
13392
|
+
throw new Error(errors.SIG_PARSE)
|
|
13393
|
+
case 2:
|
|
13394
|
+
throw new Error(errors.PUBKEY_PARSE)
|
|
13395
|
+
}
|
|
13396
|
+
},
|
|
13397
|
+
|
|
13398
|
+
ecdsaRecover (sig, recid, msg32, compressed = true, output) {
|
|
13399
|
+
isUint8Array('signature', sig, 64);
|
|
13400
|
+
assert$g(
|
|
13401
|
+
toTypeString(recid) === 'Number' &&
|
|
13402
|
+
recid >= 0 &&
|
|
13403
|
+
recid <= 3,
|
|
13404
|
+
'Expected recovery id to be a Number within interval [0, 3]'
|
|
13405
|
+
);
|
|
13406
|
+
isUint8Array('message', msg32, 32);
|
|
13407
|
+
isCompressed(compressed);
|
|
13408
|
+
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
13409
|
+
|
|
13410
|
+
switch (secp256k1.ecdsaRecover(output, sig, recid, msg32)) {
|
|
13411
|
+
case 0:
|
|
13412
|
+
return output
|
|
13413
|
+
case 1:
|
|
13414
|
+
throw new Error(errors.SIG_PARSE)
|
|
13415
|
+
case 2:
|
|
13416
|
+
throw new Error(errors.RECOVER)
|
|
13417
|
+
case 3:
|
|
13418
|
+
throw new Error(errors.IMPOSSIBLE_CASE)
|
|
13419
|
+
}
|
|
13420
|
+
},
|
|
13421
|
+
|
|
13422
|
+
ecdh (pubkey, seckey, options = {}, output) {
|
|
13423
|
+
isUint8Array('public key', pubkey, [33, 65]);
|
|
13424
|
+
isUint8Array('private key', seckey, 32);
|
|
13425
|
+
assert$g(toTypeString(options) === 'Object', 'Expected options to be an Object');
|
|
13426
|
+
if (options.data !== undefined) isUint8Array('options.data', options.data);
|
|
13427
|
+
if (options.hashfn !== undefined) {
|
|
13428
|
+
assert$g(toTypeString(options.hashfn) === 'Function', 'Expected options.hashfn to be a Function');
|
|
13429
|
+
if (options.xbuf !== undefined) isUint8Array('options.xbuf', options.xbuf, 32);
|
|
13430
|
+
if (options.ybuf !== undefined) isUint8Array('options.ybuf', options.ybuf, 32);
|
|
13431
|
+
isUint8Array('output', output);
|
|
13432
|
+
} else {
|
|
13433
|
+
output = getAssertedOutput(output, 32);
|
|
13434
|
+
}
|
|
13435
|
+
|
|
13436
|
+
switch (secp256k1.ecdh(output, pubkey, seckey, options.data, options.hashfn, options.xbuf, options.ybuf)) {
|
|
13437
|
+
case 0:
|
|
13438
|
+
return output
|
|
13439
|
+
case 1:
|
|
13440
|
+
throw new Error(errors.PUBKEY_PARSE)
|
|
13441
|
+
case 2:
|
|
13442
|
+
throw new Error(errors.ECDH)
|
|
13443
|
+
}
|
|
13444
|
+
}
|
|
13445
|
+
}
|
|
13446
|
+
};
|
|
13447
|
+
|
|
13448
|
+
var elliptic$2 = {};
|
|
13449
|
+
|
|
13450
|
+
var name = "elliptic";
|
|
13451
|
+
var version$1 = "6.5.4";
|
|
13452
|
+
var description = "EC cryptography";
|
|
13453
|
+
var main = "lib/elliptic.js";
|
|
13454
|
+
var files = [
|
|
13455
|
+
"lib"
|
|
13456
|
+
];
|
|
13457
|
+
var scripts = {
|
|
13458
|
+
lint: "eslint lib test",
|
|
13459
|
+
"lint:fix": "npm run lint -- --fix",
|
|
13460
|
+
unit: "istanbul test _mocha --reporter=spec test/index.js",
|
|
13461
|
+
test: "npm run lint && npm run unit",
|
|
13462
|
+
version: "grunt dist && git add dist/"
|
|
13463
|
+
};
|
|
13464
|
+
var repository = {
|
|
13465
|
+
type: "git",
|
|
13466
|
+
url: "git@github.com:indutny/elliptic"
|
|
13467
|
+
};
|
|
13468
|
+
var keywords = [
|
|
13469
|
+
"EC",
|
|
13470
|
+
"Elliptic",
|
|
13471
|
+
"curve",
|
|
13472
|
+
"Cryptography"
|
|
13473
|
+
];
|
|
13474
|
+
var author = "Fedor Indutny <fedor@indutny.com>";
|
|
13475
|
+
var license = "MIT";
|
|
13476
|
+
var bugs = {
|
|
13477
|
+
url: "https://github.com/indutny/elliptic/issues"
|
|
13478
|
+
};
|
|
13479
|
+
var homepage = "https://github.com/indutny/elliptic";
|
|
13480
|
+
var devDependencies = {
|
|
13481
|
+
brfs: "^2.0.2",
|
|
13482
|
+
coveralls: "^3.1.0",
|
|
13483
|
+
eslint: "^7.6.0",
|
|
13484
|
+
grunt: "^1.2.1",
|
|
13485
|
+
"grunt-browserify": "^5.3.0",
|
|
13486
|
+
"grunt-cli": "^1.3.2",
|
|
13487
|
+
"grunt-contrib-connect": "^3.0.0",
|
|
13488
|
+
"grunt-contrib-copy": "^1.0.0",
|
|
13489
|
+
"grunt-contrib-uglify": "^5.0.0",
|
|
13490
|
+
"grunt-mocha-istanbul": "^5.0.2",
|
|
13491
|
+
"grunt-saucelabs": "^9.0.1",
|
|
13492
|
+
istanbul: "^0.4.5",
|
|
13493
|
+
mocha: "^8.0.1"
|
|
13494
|
+
};
|
|
13495
|
+
var dependencies = {
|
|
13496
|
+
"bn.js": "^4.11.9",
|
|
13497
|
+
brorand: "^1.1.0",
|
|
13498
|
+
"hash.js": "^1.0.0",
|
|
13499
|
+
"hmac-drbg": "^1.0.1",
|
|
13500
|
+
inherits: "^2.0.4",
|
|
13501
|
+
"minimalistic-assert": "^1.0.1",
|
|
13502
|
+
"minimalistic-crypto-utils": "^1.0.1"
|
|
13503
|
+
};
|
|
13504
|
+
var require$$0 = {
|
|
13505
|
+
name: name,
|
|
13506
|
+
version: version$1,
|
|
13507
|
+
description: description,
|
|
13508
|
+
main: main,
|
|
13509
|
+
files: files,
|
|
13510
|
+
scripts: scripts,
|
|
13511
|
+
repository: repository,
|
|
13512
|
+
keywords: keywords,
|
|
13513
|
+
author: author,
|
|
13514
|
+
license: license,
|
|
13515
|
+
bugs: bugs,
|
|
13516
|
+
homepage: homepage,
|
|
13517
|
+
devDependencies: devDependencies,
|
|
13518
|
+
dependencies: dependencies
|
|
13519
|
+
};
|
|
13520
|
+
|
|
13521
|
+
var utils$o = {};
|
|
13522
|
+
|
|
13523
|
+
var bn = {exports: {}};
|
|
13524
|
+
|
|
13525
|
+
(function (module) {
|
|
13526
|
+
(function (module, exports) {
|
|
13527
|
+
|
|
13528
|
+
// Utils
|
|
13529
|
+
function assert (val, msg) {
|
|
13530
|
+
if (!val) throw new Error(msg || 'Assertion failed');
|
|
13531
|
+
}
|
|
13532
|
+
|
|
13533
|
+
// Could use `inherits` module, but don't want to move from single file
|
|
13534
|
+
// architecture yet.
|
|
13535
|
+
function inherits (ctor, superCtor) {
|
|
13536
|
+
ctor.super_ = superCtor;
|
|
13537
|
+
var TempCtor = function () {};
|
|
13538
|
+
TempCtor.prototype = superCtor.prototype;
|
|
13539
|
+
ctor.prototype = new TempCtor();
|
|
13540
|
+
ctor.prototype.constructor = ctor;
|
|
13541
|
+
}
|
|
13542
|
+
|
|
13543
|
+
// BN
|
|
13544
|
+
|
|
13545
|
+
function BN (number, base, endian) {
|
|
13546
|
+
if (BN.isBN(number)) {
|
|
13547
|
+
return number;
|
|
13548
|
+
}
|
|
13549
|
+
|
|
13550
|
+
this.negative = 0;
|
|
13551
|
+
this.words = null;
|
|
13552
|
+
this.length = 0;
|
|
13553
|
+
|
|
13554
|
+
// Reduction context
|
|
13555
|
+
this.red = null;
|
|
13556
|
+
|
|
13557
|
+
if (number !== null) {
|
|
13558
|
+
if (base === 'le' || base === 'be') {
|
|
13559
|
+
endian = base;
|
|
13560
|
+
base = 10;
|
|
13561
|
+
}
|
|
13562
|
+
|
|
13563
|
+
this._init(number || 0, base || 10, endian || 'be');
|
|
13564
|
+
}
|
|
13565
|
+
}
|
|
13566
|
+
if (typeof module === 'object') {
|
|
13567
|
+
module.exports = BN;
|
|
13568
|
+
} else {
|
|
13569
|
+
exports.BN = BN;
|
|
13570
|
+
}
|
|
13571
|
+
|
|
13572
|
+
BN.BN = BN;
|
|
13573
|
+
BN.wordSize = 26;
|
|
13574
|
+
|
|
13575
|
+
var Buffer;
|
|
13576
|
+
try {
|
|
13577
|
+
if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
|
|
13578
|
+
Buffer = window.Buffer;
|
|
13579
|
+
} else {
|
|
13580
|
+
Buffer = require$$3.Buffer;
|
|
13581
|
+
}
|
|
13582
|
+
} catch (e) {
|
|
13583
|
+
}
|
|
13584
|
+
|
|
13585
|
+
BN.isBN = function isBN (num) {
|
|
13586
|
+
if (num instanceof BN) {
|
|
13587
|
+
return true;
|
|
13588
|
+
}
|
|
13589
|
+
|
|
13590
|
+
return num !== null && typeof num === 'object' &&
|
|
13591
|
+
num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
|
|
13592
|
+
};
|
|
13593
|
+
|
|
13594
|
+
BN.max = function max (left, right) {
|
|
13595
|
+
if (left.cmp(right) > 0) return left;
|
|
13596
|
+
return right;
|
|
13597
|
+
};
|
|
13598
|
+
|
|
13599
|
+
BN.min = function min (left, right) {
|
|
13600
|
+
if (left.cmp(right) < 0) return left;
|
|
13601
|
+
return right;
|
|
13602
|
+
};
|
|
13603
|
+
|
|
13604
|
+
BN.prototype._init = function init (number, base, endian) {
|
|
13605
|
+
if (typeof number === 'number') {
|
|
13606
|
+
return this._initNumber(number, base, endian);
|
|
13607
|
+
}
|
|
13608
|
+
|
|
13609
|
+
if (typeof number === 'object') {
|
|
13610
|
+
return this._initArray(number, base, endian);
|
|
13611
|
+
}
|
|
13612
|
+
|
|
13613
|
+
if (base === 'hex') {
|
|
13614
|
+
base = 16;
|
|
13615
|
+
}
|
|
13616
|
+
assert(base === (base | 0) && base >= 2 && base <= 36);
|
|
13617
|
+
|
|
13618
|
+
number = number.toString().replace(/\s+/g, '');
|
|
13619
|
+
var start = 0;
|
|
13620
|
+
if (number[0] === '-') {
|
|
13621
|
+
start++;
|
|
13622
|
+
this.negative = 1;
|
|
13623
|
+
}
|
|
13624
|
+
|
|
13625
|
+
if (start < number.length) {
|
|
13626
|
+
if (base === 16) {
|
|
13288
13627
|
this._parseHex(number, start, endian);
|
|
13289
13628
|
} else {
|
|
13290
13629
|
this._parseBase(number, base, start);
|
|
@@ -16631,14 +16970,14 @@ var bn = {exports: {}};
|
|
|
16631
16970
|
|
|
16632
16971
|
var bnExports = bn.exports;
|
|
16633
16972
|
|
|
16634
|
-
var minimalisticAssert = assert$
|
|
16973
|
+
var minimalisticAssert = assert$f;
|
|
16635
16974
|
|
|
16636
|
-
function assert$
|
|
16975
|
+
function assert$f(val, msg) {
|
|
16637
16976
|
if (!val)
|
|
16638
16977
|
throw new Error(msg || 'Assertion failed');
|
|
16639
16978
|
}
|
|
16640
16979
|
|
|
16641
|
-
assert$
|
|
16980
|
+
assert$f.equal = function assertEqual(l, r, msg) {
|
|
16642
16981
|
if (l != r)
|
|
16643
16982
|
throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
|
|
16644
16983
|
};
|
|
@@ -16901,7 +17240,7 @@ var BN$8 = bnExports;
|
|
|
16901
17240
|
var utils$m = utils$o;
|
|
16902
17241
|
var getNAF = utils$m.getNAF;
|
|
16903
17242
|
var getJSF = utils$m.getJSF;
|
|
16904
|
-
var assert$
|
|
17243
|
+
var assert$e = utils$m.assert;
|
|
16905
17244
|
|
|
16906
17245
|
function BaseCurve(type, conf) {
|
|
16907
17246
|
this.type = type;
|
|
@@ -16947,7 +17286,7 @@ BaseCurve.prototype.validate = function validate() {
|
|
|
16947
17286
|
};
|
|
16948
17287
|
|
|
16949
17288
|
BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
|
|
16950
|
-
assert$
|
|
17289
|
+
assert$e(p.precomputed);
|
|
16951
17290
|
var doubles = p._getDoubles();
|
|
16952
17291
|
|
|
16953
17292
|
var naf = getNAF(k, 1, this._bitLength);
|
|
@@ -17004,7 +17343,7 @@ BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
|
|
|
17004
17343
|
if (i < 0)
|
|
17005
17344
|
break;
|
|
17006
17345
|
var z = naf[i];
|
|
17007
|
-
assert$
|
|
17346
|
+
assert$e(z !== 0);
|
|
17008
17347
|
if (p.type === 'affine') {
|
|
17009
17348
|
// J +- P
|
|
17010
17349
|
if (z > 0)
|
|
@@ -17172,9 +17511,9 @@ BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
|
|
|
17172
17511
|
if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
|
|
17173
17512
|
bytes.length - 1 === 2 * len) {
|
|
17174
17513
|
if (bytes[0] === 0x06)
|
|
17175
|
-
assert$
|
|
17514
|
+
assert$e(bytes[bytes.length - 1] % 2 === 0);
|
|
17176
17515
|
else if (bytes[0] === 0x07)
|
|
17177
|
-
assert$
|
|
17516
|
+
assert$e(bytes[bytes.length - 1] % 2 === 1);
|
|
17178
17517
|
|
|
17179
17518
|
var res = this.point(bytes.slice(1, 1 + len),
|
|
17180
17519
|
bytes.slice(1 + len, 1 + 2 * len));
|
|
@@ -17313,7 +17652,7 @@ var BN$7 = bnExports;
|
|
|
17313
17652
|
var inherits$3 = inherits_browserExports;
|
|
17314
17653
|
var Base$2 = base;
|
|
17315
17654
|
|
|
17316
|
-
var assert$
|
|
17655
|
+
var assert$d = utils$l.assert;
|
|
17317
17656
|
|
|
17318
17657
|
function ShortCurve(conf) {
|
|
17319
17658
|
Base$2.call(this, 'short', conf);
|
|
@@ -17358,7 +17697,7 @@ ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
|
|
|
17358
17697
|
lambda = lambdas[0];
|
|
17359
17698
|
} else {
|
|
17360
17699
|
lambda = lambdas[1];
|
|
17361
|
-
assert$
|
|
17700
|
+
assert$d(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
|
|
17362
17701
|
}
|
|
17363
17702
|
}
|
|
17364
17703
|
|
|
@@ -18427,7 +18766,7 @@ var BN$5 = bnExports;
|
|
|
18427
18766
|
var inherits$1 = inherits_browserExports;
|
|
18428
18767
|
var Base = base;
|
|
18429
18768
|
|
|
18430
|
-
var assert$
|
|
18769
|
+
var assert$c = utils$j.assert;
|
|
18431
18770
|
|
|
18432
18771
|
function EdwardsCurve(conf) {
|
|
18433
18772
|
// NOTE: Important as we are creating point in Base.call()
|
|
@@ -18444,7 +18783,7 @@ function EdwardsCurve(conf) {
|
|
|
18444
18783
|
this.d = new BN$5(conf.d, 16).toRed(this.red);
|
|
18445
18784
|
this.dd = this.d.redAdd(this.d);
|
|
18446
18785
|
|
|
18447
|
-
assert$
|
|
18786
|
+
assert$c(!this.twisted || this.c.fromRed().cmpn(1) === 0);
|
|
18448
18787
|
this.oneC = (conf.c | 0) === 1;
|
|
18449
18788
|
}
|
|
18450
18789
|
inherits$1(EdwardsCurve, Base);
|
|
@@ -18872,7 +19211,7 @@ var hash$2 = {};
|
|
|
18872
19211
|
|
|
18873
19212
|
var utils$i = {};
|
|
18874
19213
|
|
|
18875
|
-
var assert$
|
|
19214
|
+
var assert$b = minimalisticAssert;
|
|
18876
19215
|
var inherits = inherits_browserExports;
|
|
18877
19216
|
|
|
18878
19217
|
utils$i.inherits = inherits;
|
|
@@ -18993,7 +19332,7 @@ utils$i.zero8 = zero8;
|
|
|
18993
19332
|
|
|
18994
19333
|
function join32(msg, start, end, endian) {
|
|
18995
19334
|
var len = end - start;
|
|
18996
|
-
assert$
|
|
19335
|
+
assert$b(len % 4 === 0);
|
|
18997
19336
|
var res = new Array(len / 4);
|
|
18998
19337
|
for (var i = 0, k = start; i < res.length; i++, k += 4) {
|
|
18999
19338
|
var w;
|
|
@@ -19152,7 +19491,7 @@ utils$i.shr64_lo = shr64_lo$1;
|
|
|
19152
19491
|
var common$5 = {};
|
|
19153
19492
|
|
|
19154
19493
|
var utils$h = utils$i;
|
|
19155
|
-
var assert$
|
|
19494
|
+
var assert$a = minimalisticAssert;
|
|
19156
19495
|
|
|
19157
19496
|
function BlockHash$4() {
|
|
19158
19497
|
this.pending = null;
|
|
@@ -19197,7 +19536,7 @@ BlockHash$4.prototype.update = function update(msg, enc) {
|
|
|
19197
19536
|
|
|
19198
19537
|
BlockHash$4.prototype.digest = function digest(enc) {
|
|
19199
19538
|
this.update(this._pad());
|
|
19200
|
-
assert$
|
|
19539
|
+
assert$a(this.pending === null);
|
|
19201
19540
|
|
|
19202
19541
|
return this._digest(enc);
|
|
19203
19542
|
};
|
|
@@ -19370,7 +19709,7 @@ SHA1.prototype._digest = function digest(enc) {
|
|
|
19370
19709
|
var utils$e = utils$i;
|
|
19371
19710
|
var common$2 = common$5;
|
|
19372
19711
|
var shaCommon = common$4;
|
|
19373
|
-
var assert$
|
|
19712
|
+
var assert$9 = minimalisticAssert;
|
|
19374
19713
|
|
|
19375
19714
|
var sum32$1 = utils$e.sum32;
|
|
19376
19715
|
var sum32_4$1 = utils$e.sum32_4;
|
|
@@ -19440,7 +19779,7 @@ SHA256$1.prototype._update = function _update(msg, start) {
|
|
|
19440
19779
|
var g = this.h[6];
|
|
19441
19780
|
var h = this.h[7];
|
|
19442
19781
|
|
|
19443
|
-
assert$
|
|
19782
|
+
assert$9(this.k.length === W.length);
|
|
19444
19783
|
for (i = 0; i < W.length; i++) {
|
|
19445
19784
|
var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
|
|
19446
19785
|
var T2 = sum32$1(s0_256(a), maj32(a, b, c));
|
|
@@ -19501,7 +19840,7 @@ SHA224.prototype._digest = function digest(enc) {
|
|
|
19501
19840
|
|
|
19502
19841
|
var utils$c = utils$i;
|
|
19503
19842
|
var common$1 = common$5;
|
|
19504
|
-
var assert$
|
|
19843
|
+
var assert$8 = minimalisticAssert;
|
|
19505
19844
|
|
|
19506
19845
|
var rotr64_hi = utils$c.rotr64_hi;
|
|
19507
19846
|
var rotr64_lo = utils$c.rotr64_lo;
|
|
@@ -19636,7 +19975,7 @@ SHA512$1.prototype._update = function _update(msg, start) {
|
|
|
19636
19975
|
var hh = this.h[14];
|
|
19637
19976
|
var hl = this.h[15];
|
|
19638
19977
|
|
|
19639
|
-
assert$
|
|
19978
|
+
assert$8(this.k.length === W.length);
|
|
19640
19979
|
for (var i = 0; i < W.length; i += 2) {
|
|
19641
19980
|
var c0_hi = hh;
|
|
19642
19981
|
var c0_lo = hl;
|
|
@@ -20016,7 +20355,7 @@ var sh = [
|
|
|
20016
20355
|
];
|
|
20017
20356
|
|
|
20018
20357
|
var utils$9 = utils$i;
|
|
20019
|
-
var assert$
|
|
20358
|
+
var assert$7 = minimalisticAssert;
|
|
20020
20359
|
|
|
20021
20360
|
function Hmac(hash, key, enc) {
|
|
20022
20361
|
if (!(this instanceof Hmac))
|
|
@@ -20035,7 +20374,7 @@ Hmac.prototype._init = function init(key) {
|
|
|
20035
20374
|
// Shorten key, if needed
|
|
20036
20375
|
if (key.length > this.blockSize)
|
|
20037
20376
|
key = new this.Hash().update(key).digest();
|
|
20038
|
-
assert$
|
|
20377
|
+
assert$7(key.length <= this.blockSize);
|
|
20039
20378
|
|
|
20040
20379
|
// Add padding to key
|
|
20041
20380
|
for (var i = key.length; i < this.blockSize; i++)
|
|
@@ -21078,7 +21417,7 @@ function requireSecp256k1 () {
|
|
|
21078
21417
|
|
|
21079
21418
|
var hash$1 = hash$2;
|
|
21080
21419
|
var utils$8 = utils$n;
|
|
21081
|
-
var assert$
|
|
21420
|
+
var assert$6 = minimalisticAssert;
|
|
21082
21421
|
|
|
21083
21422
|
function HmacDRBG$1(options) {
|
|
21084
21423
|
if (!(this instanceof HmacDRBG$1))
|
|
@@ -21097,7 +21436,7 @@ function HmacDRBG$1(options) {
|
|
|
21097
21436
|
var entropy = utils$8.toArray(options.entropy, options.entropyEnc || 'hex');
|
|
21098
21437
|
var nonce = utils$8.toArray(options.nonce, options.nonceEnc || 'hex');
|
|
21099
21438
|
var pers = utils$8.toArray(options.pers, options.persEnc || 'hex');
|
|
21100
|
-
assert$
|
|
21439
|
+
assert$6(entropy.length >= (this.minEntropy / 8),
|
|
21101
21440
|
'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
|
|
21102
21441
|
this._init(entropy, nonce, pers);
|
|
21103
21442
|
}
|
|
@@ -21152,7 +21491,7 @@ HmacDRBG$1.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc)
|
|
|
21152
21491
|
entropy = utils$8.toArray(entropy, entropyEnc);
|
|
21153
21492
|
add = utils$8.toArray(add, addEnc);
|
|
21154
21493
|
|
|
21155
|
-
assert$
|
|
21494
|
+
assert$6(entropy.length >= (this.minEntropy / 8),
|
|
21156
21495
|
'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
|
|
21157
21496
|
|
|
21158
21497
|
this._update(entropy.concat(add || []));
|
|
@@ -21190,7 +21529,7 @@ HmacDRBG$1.prototype.generate = function generate(len, enc, add, addEnc) {
|
|
|
21190
21529
|
|
|
21191
21530
|
var BN$4 = bnExports;
|
|
21192
21531
|
var utils$7 = utils$o;
|
|
21193
|
-
var assert$
|
|
21532
|
+
var assert$5 = utils$7.assert;
|
|
21194
21533
|
|
|
21195
21534
|
function KeyPair$3(ec, options) {
|
|
21196
21535
|
this.ec = ec;
|
|
@@ -21275,10 +21614,10 @@ KeyPair$3.prototype._importPublic = function _importPublic(key, enc) {
|
|
|
21275
21614
|
// Weierstrass/Edwards points on the other hand have both `x` and
|
|
21276
21615
|
// `y` coordinates.
|
|
21277
21616
|
if (this.ec.curve.type === 'mont') {
|
|
21278
|
-
assert$
|
|
21617
|
+
assert$5(key.x, 'Need x coordinate');
|
|
21279
21618
|
} else if (this.ec.curve.type === 'short' ||
|
|
21280
21619
|
this.ec.curve.type === 'edwards') {
|
|
21281
|
-
assert$
|
|
21620
|
+
assert$5(key.x && key.y, 'Need both x and y coordinate');
|
|
21282
21621
|
}
|
|
21283
21622
|
this.pub = this.ec.curve.point(key.x, key.y);
|
|
21284
21623
|
return;
|
|
@@ -21289,7 +21628,7 @@ KeyPair$3.prototype._importPublic = function _importPublic(key, enc) {
|
|
|
21289
21628
|
// ECDH
|
|
21290
21629
|
KeyPair$3.prototype.derive = function derive(pub) {
|
|
21291
21630
|
if(!pub.validate()) {
|
|
21292
|
-
assert$
|
|
21631
|
+
assert$5(pub.validate(), 'public point not validated');
|
|
21293
21632
|
}
|
|
21294
21633
|
return pub.mul(this.priv).getX();
|
|
21295
21634
|
};
|
|
@@ -21311,7 +21650,7 @@ KeyPair$3.prototype.inspect = function inspect() {
|
|
|
21311
21650
|
var BN$3 = bnExports;
|
|
21312
21651
|
|
|
21313
21652
|
var utils$6 = utils$o;
|
|
21314
|
-
var assert$
|
|
21653
|
+
var assert$4 = utils$6.assert;
|
|
21315
21654
|
|
|
21316
21655
|
function Signature$3(options, enc) {
|
|
21317
21656
|
if (options instanceof Signature$3)
|
|
@@ -21320,7 +21659,7 @@ function Signature$3(options, enc) {
|
|
|
21320
21659
|
if (this._importDER(options, enc))
|
|
21321
21660
|
return;
|
|
21322
21661
|
|
|
21323
|
-
assert$
|
|
21662
|
+
assert$4(options.r && options.s, 'Signature without r or s');
|
|
21324
21663
|
this.r = new BN$3(options.r, 16);
|
|
21325
21664
|
this.s = new BN$3(options.s, 16);
|
|
21326
21665
|
if (options.recoveryParam === undefined)
|
|
@@ -21478,7 +21817,7 @@ var HmacDRBG = hmacDrbg;
|
|
|
21478
21817
|
var utils$5 = utils$o;
|
|
21479
21818
|
var curves$1 = curves$2;
|
|
21480
21819
|
var rand = brorandExports;
|
|
21481
|
-
var assert$
|
|
21820
|
+
var assert$3 = utils$5.assert;
|
|
21482
21821
|
|
|
21483
21822
|
var KeyPair$2 = key$1;
|
|
21484
21823
|
var Signature$2 = signature$1;
|
|
@@ -21489,7 +21828,7 @@ function EC$1(options) {
|
|
|
21489
21828
|
|
|
21490
21829
|
// Shortcut `elliptic.ec(curve-name)`
|
|
21491
21830
|
if (typeof options === 'string') {
|
|
21492
|
-
assert$
|
|
21831
|
+
assert$3(Object.prototype.hasOwnProperty.call(curves$1, options),
|
|
21493
21832
|
'Unknown curve ' + options);
|
|
21494
21833
|
|
|
21495
21834
|
options = curves$1[options];
|
|
@@ -21667,7 +22006,7 @@ EC$1.prototype.verify = function verify(msg, signature, key, enc) {
|
|
|
21667
22006
|
};
|
|
21668
22007
|
|
|
21669
22008
|
EC$1.prototype.recoverPubKey = function(msg, signature, j, enc) {
|
|
21670
|
-
assert$
|
|
22009
|
+
assert$3((3 & j) === j, 'The recovery param is more than two bits');
|
|
21671
22010
|
signature = new Signature$2(signature, enc);
|
|
21672
22011
|
|
|
21673
22012
|
var n = this.n;
|
|
@@ -21716,7 +22055,7 @@ EC$1.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) {
|
|
|
21716
22055
|
};
|
|
21717
22056
|
|
|
21718
22057
|
var utils$4 = utils$o;
|
|
21719
|
-
var assert$
|
|
22058
|
+
var assert$2 = utils$4.assert;
|
|
21720
22059
|
var parseBytes$2 = utils$4.parseBytes;
|
|
21721
22060
|
var cachedProperty$1 = utils$4.cachedProperty;
|
|
21722
22061
|
|
|
@@ -21790,7 +22129,7 @@ cachedProperty$1(KeyPair$1, 'messagePrefix', function messagePrefix() {
|
|
|
21790
22129
|
});
|
|
21791
22130
|
|
|
21792
22131
|
KeyPair$1.prototype.sign = function sign(message) {
|
|
21793
|
-
assert$
|
|
22132
|
+
assert$2(this._secret, 'KeyPair can only verify');
|
|
21794
22133
|
return this.eddsa.sign(message, this);
|
|
21795
22134
|
};
|
|
21796
22135
|
|
|
@@ -21799,7 +22138,7 @@ KeyPair$1.prototype.verify = function verify(message, sig) {
|
|
|
21799
22138
|
};
|
|
21800
22139
|
|
|
21801
22140
|
KeyPair$1.prototype.getSecret = function getSecret(enc) {
|
|
21802
|
-
assert$
|
|
22141
|
+
assert$2(this._secret, 'KeyPair is public only');
|
|
21803
22142
|
return utils$4.encode(this.secret(), enc);
|
|
21804
22143
|
};
|
|
21805
22144
|
|
|
@@ -21811,7 +22150,7 @@ var key = KeyPair$1;
|
|
|
21811
22150
|
|
|
21812
22151
|
var BN$1 = bnExports;
|
|
21813
22152
|
var utils$3 = utils$o;
|
|
21814
|
-
var assert$
|
|
22153
|
+
var assert$1 = utils$3.assert;
|
|
21815
22154
|
var cachedProperty = utils$3.cachedProperty;
|
|
21816
22155
|
var parseBytes$1 = utils$3.parseBytes;
|
|
21817
22156
|
|
|
@@ -21836,7 +22175,7 @@ function Signature$1(eddsa, sig) {
|
|
|
21836
22175
|
};
|
|
21837
22176
|
}
|
|
21838
22177
|
|
|
21839
|
-
assert$
|
|
22178
|
+
assert$1(sig.R && sig.S, 'Signature without R or S');
|
|
21840
22179
|
|
|
21841
22180
|
if (eddsa.isPoint(sig.R))
|
|
21842
22181
|
this._R = sig.R;
|
|
@@ -21876,13 +22215,13 @@ var signature = Signature$1;
|
|
|
21876
22215
|
var hash = hash$2;
|
|
21877
22216
|
var curves = curves$2;
|
|
21878
22217
|
var utils$2 = utils$o;
|
|
21879
|
-
var assert
|
|
22218
|
+
var assert = utils$2.assert;
|
|
21880
22219
|
var parseBytes = utils$2.parseBytes;
|
|
21881
22220
|
var KeyPair = key;
|
|
21882
22221
|
var Signature = signature;
|
|
21883
22222
|
|
|
21884
22223
|
function EDDSA(curve) {
|
|
21885
|
-
assert
|
|
22224
|
+
assert(curve === 'ed25519', 'only tested with ed25519 so far');
|
|
21886
22225
|
|
|
21887
22226
|
if (!(this instanceof EDDSA))
|
|
21888
22227
|
return new EDDSA(curve);
|
|
@@ -22301,447 +22640,110 @@ var elliptic$1 = {
|
|
|
22301
22640
|
if (s.cmp(ecparams.n) >= 0) s = new BN(0);
|
|
22302
22641
|
|
|
22303
22642
|
output.set(r.toArrayLike(Uint8Array, 'be', 32), 0);
|
|
22304
|
-
output.set(s.toArrayLike(Uint8Array, 'be', 32), 32);
|
|
22305
|
-
|
|
22306
|
-
return 0
|
|
22307
|
-
},
|
|
22308
|
-
|
|
22309
|
-
ecdsaSign (obj, message, seckey, data, noncefn) {
|
|
22310
|
-
if (noncefn) {
|
|
22311
|
-
const _noncefn = noncefn;
|
|
22312
|
-
noncefn = (counter) => {
|
|
22313
|
-
const nonce = _noncefn(message, seckey, null, data, counter);
|
|
22314
|
-
|
|
22315
|
-
const isValid = nonce instanceof Uint8Array && nonce.length === 32;
|
|
22316
|
-
if (!isValid) throw new Error('This is the way')
|
|
22317
|
-
|
|
22318
|
-
return new BN(nonce)
|
|
22319
|
-
};
|
|
22320
|
-
}
|
|
22321
|
-
|
|
22322
|
-
const d = new BN(seckey);
|
|
22323
|
-
if (d.cmp(ecparams.n) >= 0 || d.isZero()) return 1
|
|
22324
|
-
|
|
22325
|
-
let sig;
|
|
22326
|
-
try {
|
|
22327
|
-
sig = ec.sign(message, seckey, { canonical: true, k: noncefn, pers: data });
|
|
22328
|
-
} catch (err) {
|
|
22329
|
-
return 1
|
|
22330
|
-
}
|
|
22331
|
-
|
|
22332
|
-
obj.signature.set(sig.r.toArrayLike(Uint8Array, 'be', 32), 0);
|
|
22333
|
-
obj.signature.set(sig.s.toArrayLike(Uint8Array, 'be', 32), 32);
|
|
22334
|
-
obj.recid = sig.recoveryParam;
|
|
22335
|
-
|
|
22336
|
-
return 0
|
|
22337
|
-
},
|
|
22338
|
-
|
|
22339
|
-
ecdsaVerify (sig, msg32, pubkey) {
|
|
22340
|
-
const sigObj = { r: sig.subarray(0, 32), s: sig.subarray(32, 64) };
|
|
22341
|
-
|
|
22342
|
-
const sigr = new BN(sigObj.r);
|
|
22343
|
-
const sigs = new BN(sigObj.s);
|
|
22344
|
-
if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
|
|
22345
|
-
if (sigs.cmp(ec.nh) === 1 || sigr.isZero() || sigs.isZero()) return 3
|
|
22346
|
-
|
|
22347
|
-
const pair = loadPublicKey(pubkey);
|
|
22348
|
-
if (pair === null) return 2
|
|
22349
|
-
|
|
22350
|
-
const point = pair.getPublic();
|
|
22351
|
-
const isValid = ec.verify(msg32, sigObj, point);
|
|
22352
|
-
return isValid ? 0 : 3
|
|
22353
|
-
},
|
|
22354
|
-
|
|
22355
|
-
ecdsaRecover (output, sig, recid, msg32) {
|
|
22356
|
-
const sigObj = { r: sig.slice(0, 32), s: sig.slice(32, 64) };
|
|
22357
|
-
|
|
22358
|
-
const sigr = new BN(sigObj.r);
|
|
22359
|
-
const sigs = new BN(sigObj.s);
|
|
22360
|
-
if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
|
|
22361
|
-
|
|
22362
|
-
if (sigr.isZero() || sigs.isZero()) return 2
|
|
22363
|
-
|
|
22364
|
-
// Can throw `throw new Error('Unable to find sencond key candinate');`
|
|
22365
|
-
let point;
|
|
22366
|
-
try {
|
|
22367
|
-
point = ec.recoverPubKey(msg32, sigObj, recid);
|
|
22368
|
-
} catch (err) {
|
|
22369
|
-
return 2
|
|
22370
|
-
}
|
|
22371
|
-
|
|
22372
|
-
savePublicKey(output, point);
|
|
22373
|
-
|
|
22374
|
-
return 0
|
|
22375
|
-
},
|
|
22376
|
-
|
|
22377
|
-
ecdh (output, pubkey, seckey, data, hashfn, xbuf, ybuf) {
|
|
22378
|
-
const pair = loadPublicKey(pubkey);
|
|
22379
|
-
if (pair === null) return 1
|
|
22380
|
-
|
|
22381
|
-
const scalar = new BN(seckey);
|
|
22382
|
-
if (scalar.cmp(ecparams.n) >= 0 || scalar.isZero()) return 2
|
|
22383
|
-
|
|
22384
|
-
const point = pair.getPublic().mul(scalar);
|
|
22385
|
-
|
|
22386
|
-
if (hashfn === undefined) {
|
|
22387
|
-
const data = point.encode(null, true);
|
|
22388
|
-
const sha256 = ec.hash().update(data).digest();
|
|
22389
|
-
for (let i = 0; i < 32; ++i) output[i] = sha256[i];
|
|
22390
|
-
} else {
|
|
22391
|
-
if (!xbuf) xbuf = new Uint8Array(32);
|
|
22392
|
-
const x = point.getX().toArray('be', 32);
|
|
22393
|
-
for (let i = 0; i < 32; ++i) xbuf[i] = x[i];
|
|
22394
|
-
|
|
22395
|
-
if (!ybuf) ybuf = new Uint8Array(32);
|
|
22396
|
-
const y = point.getY().toArray('be', 32);
|
|
22397
|
-
for (let i = 0; i < 32; ++i) ybuf[i] = y[i];
|
|
22398
|
-
|
|
22399
|
-
const hash = hashfn(xbuf, ybuf, data);
|
|
22400
|
-
|
|
22401
|
-
const isValid = hash instanceof Uint8Array && hash.length === output.length;
|
|
22402
|
-
if (!isValid) return 2
|
|
22403
|
-
|
|
22404
|
-
output.set(hash);
|
|
22405
|
-
}
|
|
22406
|
-
|
|
22407
|
-
return 0
|
|
22408
|
-
}
|
|
22409
|
-
};
|
|
22410
|
-
|
|
22411
|
-
const errors = {
|
|
22412
|
-
IMPOSSIBLE_CASE: 'Impossible case. Please create issue.',
|
|
22413
|
-
TWEAK_ADD:
|
|
22414
|
-
'The tweak was out of range or the resulted private key is invalid',
|
|
22415
|
-
TWEAK_MUL: 'The tweak was out of range or equal to zero',
|
|
22416
|
-
CONTEXT_RANDOMIZE_UNKNOW: 'Unknow error on context randomization',
|
|
22417
|
-
SECKEY_INVALID: 'Private Key is invalid',
|
|
22418
|
-
PUBKEY_PARSE: 'Public Key could not be parsed',
|
|
22419
|
-
PUBKEY_SERIALIZE: 'Public Key serialization error',
|
|
22420
|
-
PUBKEY_COMBINE: 'The sum of the public keys is not valid',
|
|
22421
|
-
SIG_PARSE: 'Signature could not be parsed',
|
|
22422
|
-
SIGN: 'The nonce generation function failed, or the private key was invalid',
|
|
22423
|
-
RECOVER: 'Public key could not be recover',
|
|
22424
|
-
ECDH: 'Scalar was invalid (zero or overflow)'
|
|
22425
|
-
};
|
|
22426
|
-
|
|
22427
|
-
function assert (cond, msg) {
|
|
22428
|
-
if (!cond) throw new Error(msg)
|
|
22429
|
-
}
|
|
22430
|
-
|
|
22431
|
-
function isUint8Array (name, value, length) {
|
|
22432
|
-
assert(value instanceof Uint8Array, `Expected ${name} to be an Uint8Array`);
|
|
22433
|
-
|
|
22434
|
-
if (length !== undefined) {
|
|
22435
|
-
if (Array.isArray(length)) {
|
|
22436
|
-
const numbers = length.join(', ');
|
|
22437
|
-
const msg = `Expected ${name} to be an Uint8Array with length [${numbers}]`;
|
|
22438
|
-
assert(length.includes(value.length), msg);
|
|
22439
|
-
} else {
|
|
22440
|
-
const msg = `Expected ${name} to be an Uint8Array with length ${length}`;
|
|
22441
|
-
assert(value.length === length, msg);
|
|
22442
|
-
}
|
|
22443
|
-
}
|
|
22444
|
-
}
|
|
22445
|
-
|
|
22446
|
-
function isCompressed (value) {
|
|
22447
|
-
assert(toTypeString(value) === 'Boolean', 'Expected compressed to be a Boolean');
|
|
22448
|
-
}
|
|
22449
|
-
|
|
22450
|
-
function getAssertedOutput (output = (len) => new Uint8Array(len), length) {
|
|
22451
|
-
if (typeof output === 'function') output = output(length);
|
|
22452
|
-
isUint8Array('output', output, length);
|
|
22453
|
-
return output
|
|
22454
|
-
}
|
|
22455
|
-
|
|
22456
|
-
function toTypeString (value) {
|
|
22457
|
-
return Object.prototype.toString.call(value).slice(8, -1)
|
|
22458
|
-
}
|
|
22459
|
-
|
|
22460
|
-
var lib = (secp256k1) => {
|
|
22461
|
-
return {
|
|
22462
|
-
contextRandomize (seed) {
|
|
22463
|
-
assert(
|
|
22464
|
-
seed === null || seed instanceof Uint8Array,
|
|
22465
|
-
'Expected seed to be an Uint8Array or null'
|
|
22466
|
-
);
|
|
22467
|
-
if (seed !== null) isUint8Array('seed', seed, 32);
|
|
22468
|
-
|
|
22469
|
-
switch (secp256k1.contextRandomize(seed)) {
|
|
22470
|
-
case 1:
|
|
22471
|
-
throw new Error(errors.CONTEXT_RANDOMIZE_UNKNOW)
|
|
22472
|
-
}
|
|
22473
|
-
},
|
|
22474
|
-
|
|
22475
|
-
privateKeyVerify (seckey) {
|
|
22476
|
-
isUint8Array('private key', seckey, 32);
|
|
22477
|
-
|
|
22478
|
-
return secp256k1.privateKeyVerify(seckey) === 0
|
|
22479
|
-
},
|
|
22480
|
-
|
|
22481
|
-
privateKeyNegate (seckey) {
|
|
22482
|
-
isUint8Array('private key', seckey, 32);
|
|
22483
|
-
|
|
22484
|
-
switch (secp256k1.privateKeyNegate(seckey)) {
|
|
22485
|
-
case 0:
|
|
22486
|
-
return seckey
|
|
22487
|
-
case 1:
|
|
22488
|
-
throw new Error(errors.IMPOSSIBLE_CASE)
|
|
22489
|
-
}
|
|
22490
|
-
},
|
|
22491
|
-
|
|
22492
|
-
privateKeyTweakAdd (seckey, tweak) {
|
|
22493
|
-
isUint8Array('private key', seckey, 32);
|
|
22494
|
-
isUint8Array('tweak', tweak, 32);
|
|
22495
|
-
|
|
22496
|
-
switch (secp256k1.privateKeyTweakAdd(seckey, tweak)) {
|
|
22497
|
-
case 0:
|
|
22498
|
-
return seckey
|
|
22499
|
-
case 1:
|
|
22500
|
-
throw new Error(errors.TWEAK_ADD)
|
|
22501
|
-
}
|
|
22502
|
-
},
|
|
22503
|
-
|
|
22504
|
-
privateKeyTweakMul (seckey, tweak) {
|
|
22505
|
-
isUint8Array('private key', seckey, 32);
|
|
22506
|
-
isUint8Array('tweak', tweak, 32);
|
|
22507
|
-
|
|
22508
|
-
switch (secp256k1.privateKeyTweakMul(seckey, tweak)) {
|
|
22509
|
-
case 0:
|
|
22510
|
-
return seckey
|
|
22511
|
-
case 1:
|
|
22512
|
-
throw new Error(errors.TWEAK_MUL)
|
|
22513
|
-
}
|
|
22514
|
-
},
|
|
22515
|
-
|
|
22516
|
-
publicKeyVerify (pubkey) {
|
|
22517
|
-
isUint8Array('public key', pubkey, [33, 65]);
|
|
22518
|
-
|
|
22519
|
-
return secp256k1.publicKeyVerify(pubkey) === 0
|
|
22520
|
-
},
|
|
22521
|
-
|
|
22522
|
-
publicKeyCreate (seckey, compressed = true, output) {
|
|
22523
|
-
isUint8Array('private key', seckey, 32);
|
|
22524
|
-
isCompressed(compressed);
|
|
22525
|
-
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
22526
|
-
|
|
22527
|
-
switch (secp256k1.publicKeyCreate(output, seckey)) {
|
|
22528
|
-
case 0:
|
|
22529
|
-
return output
|
|
22530
|
-
case 1:
|
|
22531
|
-
throw new Error(errors.SECKEY_INVALID)
|
|
22532
|
-
case 2:
|
|
22533
|
-
throw new Error(errors.PUBKEY_SERIALIZE)
|
|
22534
|
-
}
|
|
22535
|
-
},
|
|
22643
|
+
output.set(s.toArrayLike(Uint8Array, 'be', 32), 32);
|
|
22536
22644
|
|
|
22537
|
-
|
|
22538
|
-
|
|
22539
|
-
isCompressed(compressed);
|
|
22540
|
-
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
22645
|
+
return 0
|
|
22646
|
+
},
|
|
22541
22647
|
|
|
22542
|
-
|
|
22543
|
-
|
|
22544
|
-
|
|
22545
|
-
|
|
22546
|
-
|
|
22547
|
-
case 2:
|
|
22548
|
-
throw new Error(errors.PUBKEY_SERIALIZE)
|
|
22549
|
-
}
|
|
22550
|
-
},
|
|
22648
|
+
ecdsaSign (obj, message, seckey, data, noncefn) {
|
|
22649
|
+
if (noncefn) {
|
|
22650
|
+
const _noncefn = noncefn;
|
|
22651
|
+
noncefn = (counter) => {
|
|
22652
|
+
const nonce = _noncefn(message, seckey, null, data, counter);
|
|
22551
22653
|
|
|
22552
|
-
|
|
22553
|
-
|
|
22554
|
-
isCompressed(compressed);
|
|
22555
|
-
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
22654
|
+
const isValid = nonce instanceof Uint8Array && nonce.length === 32;
|
|
22655
|
+
if (!isValid) throw new Error('This is the way')
|
|
22556
22656
|
|
|
22557
|
-
|
|
22558
|
-
|
|
22559
|
-
|
|
22560
|
-
case 1:
|
|
22561
|
-
throw new Error(errors.PUBKEY_PARSE)
|
|
22562
|
-
case 2:
|
|
22563
|
-
throw new Error(errors.IMPOSSIBLE_CASE)
|
|
22564
|
-
case 3:
|
|
22565
|
-
throw new Error(errors.PUBKEY_SERIALIZE)
|
|
22566
|
-
}
|
|
22567
|
-
},
|
|
22657
|
+
return new BN(nonce)
|
|
22658
|
+
};
|
|
22659
|
+
}
|
|
22568
22660
|
|
|
22569
|
-
|
|
22570
|
-
|
|
22571
|
-
assert(pubkeys.length > 0, 'Expected public keys array will have more than zero items');
|
|
22572
|
-
for (const pubkey of pubkeys) {
|
|
22573
|
-
isUint8Array('public key', pubkey, [33, 65]);
|
|
22574
|
-
}
|
|
22575
|
-
isCompressed(compressed);
|
|
22576
|
-
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
22661
|
+
const d = new BN(seckey);
|
|
22662
|
+
if (d.cmp(ecparams.n) >= 0 || d.isZero()) return 1
|
|
22577
22663
|
|
|
22578
|
-
|
|
22579
|
-
|
|
22580
|
-
|
|
22581
|
-
|
|
22582
|
-
|
|
22583
|
-
|
|
22584
|
-
throw new Error(errors.PUBKEY_COMBINE)
|
|
22585
|
-
case 3:
|
|
22586
|
-
throw new Error(errors.PUBKEY_SERIALIZE)
|
|
22587
|
-
}
|
|
22588
|
-
},
|
|
22664
|
+
let sig;
|
|
22665
|
+
try {
|
|
22666
|
+
sig = ec.sign(message, seckey, { canonical: true, k: noncefn, pers: data });
|
|
22667
|
+
} catch (err) {
|
|
22668
|
+
return 1
|
|
22669
|
+
}
|
|
22589
22670
|
|
|
22590
|
-
|
|
22591
|
-
|
|
22592
|
-
|
|
22593
|
-
isCompressed(compressed);
|
|
22594
|
-
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
22671
|
+
obj.signature.set(sig.r.toArrayLike(Uint8Array, 'be', 32), 0);
|
|
22672
|
+
obj.signature.set(sig.s.toArrayLike(Uint8Array, 'be', 32), 32);
|
|
22673
|
+
obj.recid = sig.recoveryParam;
|
|
22595
22674
|
|
|
22596
|
-
|
|
22597
|
-
|
|
22598
|
-
return output
|
|
22599
|
-
case 1:
|
|
22600
|
-
throw new Error(errors.PUBKEY_PARSE)
|
|
22601
|
-
case 2:
|
|
22602
|
-
throw new Error(errors.TWEAK_ADD)
|
|
22603
|
-
}
|
|
22604
|
-
},
|
|
22675
|
+
return 0
|
|
22676
|
+
},
|
|
22605
22677
|
|
|
22606
|
-
|
|
22607
|
-
|
|
22608
|
-
isUint8Array('tweak', tweak, 32);
|
|
22609
|
-
isCompressed(compressed);
|
|
22610
|
-
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
22678
|
+
ecdsaVerify (sig, msg32, pubkey) {
|
|
22679
|
+
const sigObj = { r: sig.subarray(0, 32), s: sig.subarray(32, 64) };
|
|
22611
22680
|
|
|
22612
|
-
|
|
22613
|
-
|
|
22614
|
-
|
|
22615
|
-
|
|
22616
|
-
throw new Error(errors.PUBKEY_PARSE)
|
|
22617
|
-
case 2:
|
|
22618
|
-
throw new Error(errors.TWEAK_MUL)
|
|
22619
|
-
}
|
|
22620
|
-
},
|
|
22681
|
+
const sigr = new BN(sigObj.r);
|
|
22682
|
+
const sigs = new BN(sigObj.s);
|
|
22683
|
+
if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
|
|
22684
|
+
if (sigs.cmp(ec.nh) === 1 || sigr.isZero() || sigs.isZero()) return 3
|
|
22621
22685
|
|
|
22622
|
-
|
|
22623
|
-
|
|
22686
|
+
const pair = loadPublicKey(pubkey);
|
|
22687
|
+
if (pair === null) return 2
|
|
22624
22688
|
|
|
22625
|
-
|
|
22626
|
-
|
|
22627
|
-
|
|
22628
|
-
|
|
22629
|
-
throw new Error(errors.SIG_PARSE)
|
|
22630
|
-
}
|
|
22631
|
-
},
|
|
22689
|
+
const point = pair.getPublic();
|
|
22690
|
+
const isValid = ec.verify(msg32, sigObj, point);
|
|
22691
|
+
return isValid ? 0 : 3
|
|
22692
|
+
},
|
|
22632
22693
|
|
|
22633
|
-
|
|
22634
|
-
|
|
22635
|
-
output = getAssertedOutput(output, 72);
|
|
22694
|
+
ecdsaRecover (output, sig, recid, msg32) {
|
|
22695
|
+
const sigObj = { r: sig.slice(0, 32), s: sig.slice(32, 64) };
|
|
22636
22696
|
|
|
22637
|
-
|
|
22638
|
-
|
|
22639
|
-
|
|
22640
|
-
return output.slice(0, obj.outputlen)
|
|
22641
|
-
case 1:
|
|
22642
|
-
throw new Error(errors.SIG_PARSE)
|
|
22643
|
-
case 2:
|
|
22644
|
-
throw new Error(errors.IMPOSSIBLE_CASE)
|
|
22645
|
-
}
|
|
22646
|
-
},
|
|
22697
|
+
const sigr = new BN(sigObj.r);
|
|
22698
|
+
const sigs = new BN(sigObj.s);
|
|
22699
|
+
if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
|
|
22647
22700
|
|
|
22648
|
-
|
|
22649
|
-
isUint8Array('signature', sig);
|
|
22650
|
-
output = getAssertedOutput(output, 64);
|
|
22701
|
+
if (sigr.isZero() || sigs.isZero()) return 2
|
|
22651
22702
|
|
|
22652
|
-
|
|
22653
|
-
|
|
22654
|
-
|
|
22655
|
-
|
|
22656
|
-
|
|
22657
|
-
|
|
22658
|
-
|
|
22659
|
-
}
|
|
22660
|
-
},
|
|
22703
|
+
// Can throw `throw new Error('Unable to find sencond key candinate');`
|
|
22704
|
+
let point;
|
|
22705
|
+
try {
|
|
22706
|
+
point = ec.recoverPubKey(msg32, sigObj, recid);
|
|
22707
|
+
} catch (err) {
|
|
22708
|
+
return 2
|
|
22709
|
+
}
|
|
22661
22710
|
|
|
22662
|
-
|
|
22663
|
-
isUint8Array('message', msg32, 32);
|
|
22664
|
-
isUint8Array('private key', seckey, 32);
|
|
22665
|
-
assert(toTypeString(options) === 'Object', 'Expected options to be an Object');
|
|
22666
|
-
if (options.data !== undefined) isUint8Array('options.data', options.data);
|
|
22667
|
-
if (options.noncefn !== undefined) assert(toTypeString(options.noncefn) === 'Function', 'Expected options.noncefn to be a Function');
|
|
22668
|
-
output = getAssertedOutput(output, 64);
|
|
22711
|
+
savePublicKey(output, point);
|
|
22669
22712
|
|
|
22670
|
-
|
|
22671
|
-
|
|
22672
|
-
case 0:
|
|
22673
|
-
return obj
|
|
22674
|
-
case 1:
|
|
22675
|
-
throw new Error(errors.SIGN)
|
|
22676
|
-
case 2:
|
|
22677
|
-
throw new Error(errors.IMPOSSIBLE_CASE)
|
|
22678
|
-
}
|
|
22679
|
-
},
|
|
22713
|
+
return 0
|
|
22714
|
+
},
|
|
22680
22715
|
|
|
22681
|
-
|
|
22682
|
-
|
|
22683
|
-
|
|
22684
|
-
isUint8Array('public key', pubkey, [33, 65]);
|
|
22716
|
+
ecdh (output, pubkey, seckey, data, hashfn, xbuf, ybuf) {
|
|
22717
|
+
const pair = loadPublicKey(pubkey);
|
|
22718
|
+
if (pair === null) return 1
|
|
22685
22719
|
|
|
22686
|
-
|
|
22687
|
-
|
|
22688
|
-
return true
|
|
22689
|
-
case 3:
|
|
22690
|
-
return false
|
|
22691
|
-
case 1:
|
|
22692
|
-
throw new Error(errors.SIG_PARSE)
|
|
22693
|
-
case 2:
|
|
22694
|
-
throw new Error(errors.PUBKEY_PARSE)
|
|
22695
|
-
}
|
|
22696
|
-
},
|
|
22720
|
+
const scalar = new BN(seckey);
|
|
22721
|
+
if (scalar.cmp(ecparams.n) >= 0 || scalar.isZero()) return 2
|
|
22697
22722
|
|
|
22698
|
-
|
|
22699
|
-
isUint8Array('signature', sig, 64);
|
|
22700
|
-
assert(
|
|
22701
|
-
toTypeString(recid) === 'Number' &&
|
|
22702
|
-
recid >= 0 &&
|
|
22703
|
-
recid <= 3,
|
|
22704
|
-
'Expected recovery id to be a Number within interval [0, 3]'
|
|
22705
|
-
);
|
|
22706
|
-
isUint8Array('message', msg32, 32);
|
|
22707
|
-
isCompressed(compressed);
|
|
22708
|
-
output = getAssertedOutput(output, compressed ? 33 : 65);
|
|
22723
|
+
const point = pair.getPublic().mul(scalar);
|
|
22709
22724
|
|
|
22710
|
-
|
|
22711
|
-
|
|
22712
|
-
|
|
22713
|
-
|
|
22714
|
-
|
|
22715
|
-
|
|
22716
|
-
|
|
22717
|
-
|
|
22718
|
-
throw new Error(errors.IMPOSSIBLE_CASE)
|
|
22719
|
-
}
|
|
22720
|
-
},
|
|
22725
|
+
if (hashfn === undefined) {
|
|
22726
|
+
const data = point.encode(null, true);
|
|
22727
|
+
const sha256 = ec.hash().update(data).digest();
|
|
22728
|
+
for (let i = 0; i < 32; ++i) output[i] = sha256[i];
|
|
22729
|
+
} else {
|
|
22730
|
+
if (!xbuf) xbuf = new Uint8Array(32);
|
|
22731
|
+
const x = point.getX().toArray('be', 32);
|
|
22732
|
+
for (let i = 0; i < 32; ++i) xbuf[i] = x[i];
|
|
22721
22733
|
|
|
22722
|
-
|
|
22723
|
-
|
|
22724
|
-
|
|
22725
|
-
assert(toTypeString(options) === 'Object', 'Expected options to be an Object');
|
|
22726
|
-
if (options.data !== undefined) isUint8Array('options.data', options.data);
|
|
22727
|
-
if (options.hashfn !== undefined) {
|
|
22728
|
-
assert(toTypeString(options.hashfn) === 'Function', 'Expected options.hashfn to be a Function');
|
|
22729
|
-
if (options.xbuf !== undefined) isUint8Array('options.xbuf', options.xbuf, 32);
|
|
22730
|
-
if (options.ybuf !== undefined) isUint8Array('options.ybuf', options.ybuf, 32);
|
|
22731
|
-
isUint8Array('output', output);
|
|
22732
|
-
} else {
|
|
22733
|
-
output = getAssertedOutput(output, 32);
|
|
22734
|
-
}
|
|
22734
|
+
if (!ybuf) ybuf = new Uint8Array(32);
|
|
22735
|
+
const y = point.getY().toArray('be', 32);
|
|
22736
|
+
for (let i = 0; i < 32; ++i) ybuf[i] = y[i];
|
|
22735
22737
|
|
|
22736
|
-
|
|
22737
|
-
|
|
22738
|
-
|
|
22739
|
-
|
|
22740
|
-
|
|
22741
|
-
|
|
22742
|
-
throw new Error(errors.ECDH)
|
|
22743
|
-
}
|
|
22738
|
+
const hash = hashfn(xbuf, ybuf, data);
|
|
22739
|
+
|
|
22740
|
+
const isValid = hash instanceof Uint8Array && hash.length === output.length;
|
|
22741
|
+
if (!isValid) return 2
|
|
22742
|
+
|
|
22743
|
+
output.set(hash);
|
|
22744
22744
|
}
|
|
22745
|
+
|
|
22746
|
+
return 0
|
|
22745
22747
|
}
|
|
22746
22748
|
};
|
|
22747
22749
|
|
|
@@ -27196,7 +27198,7 @@ class Identity {
|
|
|
27196
27198
|
this.selectedAccount = new TextDecoder().decode(selected);
|
|
27197
27199
|
}
|
|
27198
27200
|
else {
|
|
27199
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
27201
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-G74WLzL7-tmiSHjUc.js');
|
|
27200
27202
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
27201
27203
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
27202
27204
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -27388,7 +27390,7 @@ class Peernet {
|
|
|
27388
27390
|
this.root = options.root;
|
|
27389
27391
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
27390
27392
|
// FolderMessageResponse
|
|
27391
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
27393
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-lWRTai7t-Bc6ghkkt.js');
|
|
27392
27394
|
/**
|
|
27393
27395
|
* proto Object containing protos
|
|
27394
27396
|
* @type {Object}
|
|
@@ -27482,7 +27484,7 @@ class Peernet {
|
|
|
27482
27484
|
if (this.#starting || this.#started)
|
|
27483
27485
|
return;
|
|
27484
27486
|
this.#starting = true;
|
|
27485
|
-
const importee = await import('./client-
|
|
27487
|
+
const importee = await import('./client-A009z8av-uBa1w1TW.js');
|
|
27486
27488
|
/**
|
|
27487
27489
|
* @access public
|
|
27488
27490
|
* @type {PeernetClient}
|