@ckb-ccc/core 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/address/address.advanced.d.ts.map +1 -1
- package/dist/address/address.advanced.js +6 -2
- package/dist/bytes/index.d.ts +21 -0
- package/dist/bytes/index.d.ts.map +1 -1
- package/dist/bytes/index.js +31 -4
- package/dist/ckb/script.d.ts +1 -1
- package/dist/ckb/script.d.ts.map +1 -1
- package/dist/ckb/script.js +2 -4
- package/dist/ckb/transaction.d.ts +19 -12
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +23 -38
- package/dist/client/clientPublicMainnet.d.ts +4 -4
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.d.ts +4 -4
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +3 -0
- package/dist/client/jsonRpc/index.d.ts +4 -0
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +11 -0
- package/dist/molecule/codec.d.ts +2 -0
- package/dist/molecule/codec.d.ts.map +1 -1
- package/dist/molecule/codec.js +51 -41
- package/dist/molecule/entity.d.ts +25 -4
- package/dist/molecule/entity.d.ts.map +1 -1
- package/dist/molecule/entity.js +22 -1
- package/dist/num/index.d.ts.map +1 -1
- package/dist/num/index.js +2 -2
- package/dist/signer/btc/verify.js +1 -1
- package/dist/signer/doge/verify.d.ts.map +1 -1
- package/dist/signer/doge/verify.js +3 -1
- package/dist.commonjs/address/address.advanced.d.ts.map +1 -1
- package/dist.commonjs/address/address.advanced.js +6 -2
- package/dist.commonjs/bytes/index.d.ts +21 -0
- package/dist.commonjs/bytes/index.d.ts.map +1 -1
- package/dist.commonjs/bytes/index.js +32 -4
- package/dist.commonjs/ckb/script.d.ts +1 -1
- package/dist.commonjs/ckb/script.d.ts.map +1 -1
- package/dist.commonjs/ckb/script.js +2 -4
- package/dist.commonjs/ckb/transaction.d.ts +19 -12
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +23 -38
- package/dist.commonjs/client/clientPublicMainnet.d.ts +4 -4
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.d.ts +4 -4
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.js +3 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts +4 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +11 -0
- package/dist.commonjs/molecule/codec.d.ts +2 -0
- package/dist.commonjs/molecule/codec.d.ts.map +1 -1
- package/dist.commonjs/molecule/codec.js +50 -40
- package/dist.commonjs/molecule/entity.d.ts +25 -4
- package/dist.commonjs/molecule/entity.d.ts.map +1 -1
- package/dist.commonjs/molecule/entity.js +22 -1
- package/dist.commonjs/num/index.d.ts.map +1 -1
- package/dist.commonjs/num/index.js +2 -2
- package/dist.commonjs/signer/btc/verify.js +1 -1
- package/dist.commonjs/signer/doge/verify.d.ts.map +1 -1
- package/dist.commonjs/signer/doge/verify.js +3 -1
- package/package.json +1 -1
- package/src/address/address.advanced.ts +6 -2
- package/src/bytes/index.ts +36 -6
- package/src/ckb/script.ts +5 -7
- package/src/ckb/transaction.ts +43 -58
- package/src/client/clientPublicMainnet.ts +4 -3
- package/src/client/clientPublicTestnet.ts +9 -3
- package/src/client/jsonRpc/index.ts +24 -1
- package/src/molecule/codec.ts +73 -61
- package/src/molecule/entity.ts +25 -5
- package/src/num/index.ts +2 -5
- package/src/signer/btc/verify.ts +1 -1
- package/src/signer/doge/verify.ts +3 -1
|
@@ -126,12 +126,10 @@ let OutPoint = OutPoint_1 = class OutPoint extends index_js_5.mol.Entity.Base()
|
|
|
126
126
|
};
|
|
127
127
|
exports.OutPoint = OutPoint;
|
|
128
128
|
exports.OutPoint = OutPoint = OutPoint_1 = __decorate([
|
|
129
|
-
index_js_5.mol.codec(index_js_5.mol
|
|
130
|
-
.struct({
|
|
129
|
+
index_js_5.mol.codec(index_js_5.mol.struct({
|
|
131
130
|
txHash: index_js_5.mol.Byte32,
|
|
132
131
|
index: index_js_5.mol.Uint32,
|
|
133
|
-
})
|
|
134
|
-
.map({ outMap: (decoded) => OutPoint.from(decoded) }))
|
|
132
|
+
}))
|
|
135
133
|
], OutPoint);
|
|
136
134
|
/**
|
|
137
135
|
* @public
|
|
@@ -177,13 +175,11 @@ let CellOutput = CellOutput_1 = class CellOutput extends index_js_5.mol.Entity.B
|
|
|
177
175
|
};
|
|
178
176
|
exports.CellOutput = CellOutput;
|
|
179
177
|
exports.CellOutput = CellOutput = CellOutput_1 = __decorate([
|
|
180
|
-
index_js_5.mol.codec(index_js_5.mol
|
|
181
|
-
.table({
|
|
178
|
+
index_js_5.mol.codec(index_js_5.mol.table({
|
|
182
179
|
capacity: index_js_5.mol.Uint64,
|
|
183
180
|
lock: script_js_1.Script,
|
|
184
181
|
type: script_js_1.ScriptOpt,
|
|
185
|
-
})
|
|
186
|
-
.map({ outMap: (decoded) => CellOutput.from(decoded) }))
|
|
182
|
+
}))
|
|
187
183
|
], CellOutput);
|
|
188
184
|
exports.CellOutputVec = index_js_5.mol.vector(CellOutput);
|
|
189
185
|
/**
|
|
@@ -345,10 +341,7 @@ let Since = Since_1 = class Since extends index_js_5.mol.Entity.Base() {
|
|
|
345
341
|
};
|
|
346
342
|
exports.Since = Since;
|
|
347
343
|
exports.Since = Since = Since_1 = __decorate([
|
|
348
|
-
index_js_5.mol.codec(index_js_5.mol.Uint64.
|
|
349
|
-
inMap: (encodable) => Since.from(encodable).toNum(),
|
|
350
|
-
outMap: (decoded) => Since.from(decoded),
|
|
351
|
-
}))
|
|
344
|
+
index_js_5.mol.codec(index_js_5.mol.Uint64.mapIn((encodable) => Since.from(encodable).toNum()))
|
|
352
345
|
], Since);
|
|
353
346
|
/**
|
|
354
347
|
* @public
|
|
@@ -418,10 +411,10 @@ exports.CellInput = CellInput = CellInput_1 = __decorate([
|
|
|
418
411
|
since: Since,
|
|
419
412
|
previousOutput: OutPoint,
|
|
420
413
|
})
|
|
421
|
-
.
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
}))
|
|
414
|
+
.mapIn((encodable) => ({
|
|
415
|
+
...encodable,
|
|
416
|
+
since: encodable.since ?? 0,
|
|
417
|
+
})))
|
|
425
418
|
], CellInput);
|
|
426
419
|
exports.CellInputVec = index_js_5.mol.vector(CellInput);
|
|
427
420
|
/**
|
|
@@ -475,12 +468,10 @@ let CellDep = CellDep_1 = class CellDep extends index_js_5.mol.Entity.Base() {
|
|
|
475
468
|
};
|
|
476
469
|
exports.CellDep = CellDep;
|
|
477
470
|
exports.CellDep = CellDep = CellDep_1 = __decorate([
|
|
478
|
-
index_js_5.mol.codec(index_js_5.mol
|
|
479
|
-
.struct({
|
|
471
|
+
index_js_5.mol.codec(index_js_5.mol.struct({
|
|
480
472
|
outPoint: OutPoint,
|
|
481
473
|
depType: exports.DepTypeCodec,
|
|
482
|
-
})
|
|
483
|
-
.map({ outMap: (decoded) => CellDep.from(decoded) }))
|
|
474
|
+
}))
|
|
484
475
|
], CellDep);
|
|
485
476
|
exports.CellDepVec = index_js_5.mol.vector(CellDep);
|
|
486
477
|
/**
|
|
@@ -524,13 +515,11 @@ let WitnessArgs = WitnessArgs_1 = class WitnessArgs extends index_js_5.mol.Entit
|
|
|
524
515
|
};
|
|
525
516
|
exports.WitnessArgs = WitnessArgs;
|
|
526
517
|
exports.WitnessArgs = WitnessArgs = WitnessArgs_1 = __decorate([
|
|
527
|
-
index_js_5.mol.codec(index_js_5.mol
|
|
528
|
-
.table({
|
|
518
|
+
index_js_5.mol.codec(index_js_5.mol.table({
|
|
529
519
|
lock: index_js_5.mol.BytesOpt,
|
|
530
520
|
inputType: index_js_5.mol.BytesOpt,
|
|
531
521
|
outputType: index_js_5.mol.BytesOpt,
|
|
532
|
-
})
|
|
533
|
-
.map({ outMap: (decoded) => WitnessArgs.from(decoded) }))
|
|
522
|
+
}))
|
|
534
523
|
], WitnessArgs);
|
|
535
524
|
/**
|
|
536
525
|
* @public
|
|
@@ -542,16 +531,14 @@ function udtBalanceFrom(dataLike) {
|
|
|
542
531
|
}
|
|
543
532
|
return (0, index_js_6.numFromBytes)(data);
|
|
544
533
|
}
|
|
545
|
-
exports.RawTransaction = index_js_5.mol
|
|
546
|
-
.table({
|
|
534
|
+
exports.RawTransaction = index_js_5.mol.table({
|
|
547
535
|
version: index_js_5.mol.Uint32,
|
|
548
536
|
cellDeps: exports.CellDepVec,
|
|
549
537
|
headerDeps: index_js_5.mol.Byte32Vec,
|
|
550
538
|
inputs: exports.CellInputVec,
|
|
551
539
|
outputs: exports.CellOutputVec,
|
|
552
540
|
outputsData: index_js_5.mol.BytesVec,
|
|
553
|
-
})
|
|
554
|
-
.map({ outMap: (decoded) => Transaction.from(decoded) });
|
|
541
|
+
});
|
|
555
542
|
/**
|
|
556
543
|
* @public
|
|
557
544
|
*/
|
|
@@ -1235,14 +1222,12 @@ exports.Transaction = Transaction = Transaction_1 = __decorate([
|
|
|
1235
1222
|
raw: exports.RawTransaction,
|
|
1236
1223
|
witnesses: index_js_5.mol.BytesVec,
|
|
1237
1224
|
})
|
|
1238
|
-
.
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
}
|
|
1246
|
-
outMap: (tx) => Transaction.from({ ...tx.raw, witnesses: tx.witnesses }),
|
|
1247
|
-
}))
|
|
1225
|
+
.mapIn((txLike) => {
|
|
1226
|
+
const tx = Transaction.from(txLike);
|
|
1227
|
+
return {
|
|
1228
|
+
raw: tx,
|
|
1229
|
+
witnesses: tx.witnesses,
|
|
1230
|
+
};
|
|
1231
|
+
})
|
|
1232
|
+
.mapOut((tx) => Transaction.from({ ...tx.raw, witnesses: tx.witnesses })))
|
|
1248
1233
|
], Transaction);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ClientCache } from "./cache/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import { KnownScript, ScriptInfo } from "./clientTypes.js";
|
|
2
|
+
import { KnownScript, ScriptInfo, ScriptInfoLike } from "./clientTypes.js";
|
|
4
3
|
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
5
4
|
/**
|
|
6
5
|
* @public
|
|
@@ -10,10 +9,11 @@ export declare class ClientPublicMainnet extends ClientJsonRpc {
|
|
|
10
9
|
constructor(config?: {
|
|
11
10
|
url?: string;
|
|
12
11
|
timeout?: number;
|
|
13
|
-
|
|
12
|
+
maxConcurrent?: number;
|
|
13
|
+
scripts?: Record<KnownScript, ScriptInfoLike | undefined>;
|
|
14
14
|
cache?: ClientCache;
|
|
15
15
|
} | undefined);
|
|
16
|
-
get scripts():
|
|
16
|
+
get scripts(): Record<KnownScript, ScriptInfoLike | undefined>;
|
|
17
17
|
get addressPrefix(): string;
|
|
18
18
|
getKnownScript(script: KnownScript): Promise<ScriptInfo>;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPublicMainnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"clientPublicMainnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IAElD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAP,MAAM,CAAC,EAAE;QACxB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAAC;QAC1D,KAAK,CAAC,EAAE,WAAW,CAAC;KACrB,YAAA;IAWH,IAAI,OAAO,IAAI,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAE7D;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAEK,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;CAS/D"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ClientCache } from "./cache/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import { KnownScript, ScriptInfo } from "./clientTypes.js";
|
|
2
|
+
import { KnownScript, ScriptInfo, ScriptInfoLike } from "./clientTypes.js";
|
|
4
3
|
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
5
4
|
/**
|
|
6
5
|
* @public
|
|
@@ -10,10 +9,11 @@ export declare class ClientPublicTestnet extends ClientJsonRpc {
|
|
|
10
9
|
constructor(config?: {
|
|
11
10
|
url?: string;
|
|
12
11
|
timeout?: number;
|
|
13
|
-
|
|
12
|
+
maxConcurrent?: number;
|
|
13
|
+
scripts?: Record<KnownScript, ScriptInfoLike | undefined>;
|
|
14
14
|
cache?: ClientCache;
|
|
15
15
|
} | undefined);
|
|
16
|
-
get scripts():
|
|
16
|
+
get scripts(): Record<KnownScript, ScriptInfoLike | undefined>;
|
|
17
17
|
get addressPrefix(): string;
|
|
18
18
|
getKnownScript(script: KnownScript): Promise<ScriptInfo>;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPublicTestnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"clientPublicTestnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IAElD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAP,MAAM,CAAC,EAAE;QACxB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAAC;QAC1D,KAAK,CAAC,EAAE,WAAW,CAAC;KACrB,YAAA;IAWH,IAAI,OAAO,IAAI,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC,CAE7D;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAEK,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;CAS/D"}
|
|
@@ -27,6 +27,9 @@ class ClientPublicTestnet extends index_js_1.ClientJsonRpc {
|
|
|
27
27
|
}
|
|
28
28
|
async getKnownScript(script) {
|
|
29
29
|
const found = this.scripts[script];
|
|
30
|
+
if (!found) {
|
|
31
|
+
throw new Error(`No script information was found for ${script} on ${this.addressPrefix}`);
|
|
32
|
+
}
|
|
30
33
|
return clientTypes_js_1.ScriptInfo.from(found);
|
|
31
34
|
}
|
|
32
35
|
}
|
|
@@ -11,6 +11,9 @@ import { JsonRpcPayload } from "../transports/advanced.js";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare abstract class ClientJsonRpc extends Client {
|
|
13
13
|
private readonly url_;
|
|
14
|
+
private readonly maxConcurrent?;
|
|
15
|
+
private concurrent;
|
|
16
|
+
private readonly pending;
|
|
14
17
|
private id;
|
|
15
18
|
private readonly transport;
|
|
16
19
|
/**
|
|
@@ -22,6 +25,7 @@ export declare abstract class ClientJsonRpc extends Client {
|
|
|
22
25
|
constructor(url_: string, config?: {
|
|
23
26
|
timeout?: number;
|
|
24
27
|
cache?: ClientCache;
|
|
28
|
+
maxConcurrent?: number;
|
|
25
29
|
});
|
|
26
30
|
/**
|
|
27
31
|
* Returns the URL of the JSON-RPC server.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAEJ,YAAY,EACZ,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,OAAO,EAAqB,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,yBAAyB,EAOzB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,cAAc,EAGf,MAAM,2BAA2B,CAAC;AAgEnC;;;GAGG;AAEH,8BAAsB,aAAc,SAAQ,MAAM;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAEJ,YAAY,EACZ,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAA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cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,GACnC,CAAC,GAAG,GAAG,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC;IAsC1C;;;;;;;OAOG;IACG,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IA6BrD;;;;;;OAMG;IAEH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,cAAc;CAQ7D"}
|
|
@@ -64,6 +64,8 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
64
64
|
constructor(url_, config) {
|
|
65
65
|
super(config);
|
|
66
66
|
this.url_ = url_;
|
|
67
|
+
this.concurrent = 0;
|
|
68
|
+
this.pending = [];
|
|
67
69
|
this.id = 0;
|
|
68
70
|
/**
|
|
69
71
|
* Get fee rate statistics
|
|
@@ -186,6 +188,7 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
186
188
|
* @returns The sum of cells capacity.
|
|
187
189
|
*/
|
|
188
190
|
this.getCellsCapacity = this.buildSender("get_cells_capacity", [advanced_js_2.JsonRpcTransformers.indexerSearchKeyFrom], ({ capacity }) => (0, index_js_3.numFrom)(capacity));
|
|
191
|
+
this.maxConcurrent = config?.maxConcurrent;
|
|
189
192
|
this.transport = (0, advanced_js_1.transportFromUri)(url_, config);
|
|
190
193
|
}
|
|
191
194
|
/**
|
|
@@ -258,7 +261,15 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
258
261
|
* @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
|
|
259
262
|
*/
|
|
260
263
|
async send(payload) {
|
|
264
|
+
if (this.maxConcurrent !== undefined &&
|
|
265
|
+
this.concurrent >= this.maxConcurrent) {
|
|
266
|
+
const pending = new Promise((resolve) => this.pending.push(resolve));
|
|
267
|
+
await pending;
|
|
268
|
+
}
|
|
269
|
+
this.concurrent += 1;
|
|
261
270
|
const res = (await this.transport.request(payload));
|
|
271
|
+
this.concurrent -= 1;
|
|
272
|
+
this.pending.pop()?.();
|
|
262
273
|
if (res.id !== payload.id) {
|
|
263
274
|
throw new Error(`Id mismatched, got ${res.id}, expected ${payload.id}`);
|
|
264
275
|
}
|
|
@@ -15,6 +15,8 @@ export declare class Codec<Encodable, Decoded = Encodable> {
|
|
|
15
15
|
inMap?: (encodable: NewEncodable) => Encodable;
|
|
16
16
|
outMap?: (decoded: Decoded) => NewDecoded;
|
|
17
17
|
}): Codec<NewEncodable, NewDecoded>;
|
|
18
|
+
mapIn<NewEncodable>(map: (encodable: NewEncodable) => Encodable): Codec<NewEncodable, Decoded>;
|
|
19
|
+
mapOut<NewDecoded>(map: (decoded: Decoded) => NewDecoded): Codec<Encodable, NewDecoded>;
|
|
18
20
|
}
|
|
19
21
|
export type EncodableType<T extends CodecLike<any, any>> = T extends CodecLike<infer Encodable, unknown> ? Encodable : never;
|
|
20
22
|
export type DecodedType<T extends CodecLike<any, any>> = T extends CodecLike<any, infer Decoded> ? Decoded : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/molecule/codec.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/molecule/codec.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,EAIL,SAAS,EACV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,GAAG,EAIH,OAAO,EAER,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,SAAS,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,IAAI;IACtD,QAAQ,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,KAAK,CAAC;IACjD,QAAQ,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO,CAAC;IACnD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;A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,CAAC,CAAC,CAAC,CAAC,CA0D3C;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CACpB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,EAC7C,SAAS,SAAS,eAAe,CAAC,CAAC,CAAC,EACpC,OAAO,SAAS,aAAa,CAAC,CAAC,CAAC,EAChC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAyC3C;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,SAAS,EAAE,OAAO,EACtC,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,EACxC,SAAS,EAAE,MAAM,GAChB,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAwCzC;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAClB,UAAU,EAAE,MAAM,EAClB,YAAY,UAAQ,GACnB,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAkBrB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,MAAM,EAClB,YAAY,UAAQ,GACnB,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAOxB"}
|
|
@@ -33,6 +33,12 @@ class Codec {
|
|
|
33
33
|
: this.decode(buffer)),
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
+
mapIn(map) {
|
|
37
|
+
return this.map({ inMap: map });
|
|
38
|
+
}
|
|
39
|
+
mapOut(map) {
|
|
40
|
+
return this.map({ outMap: map });
|
|
41
|
+
}
|
|
36
42
|
}
|
|
37
43
|
exports.Codec = Codec;
|
|
38
44
|
function uint32To(numLike) {
|
|
@@ -53,7 +59,12 @@ function fixedItemVec(itemCodec) {
|
|
|
53
59
|
return Codec.from({
|
|
54
60
|
encode(userDefinedItems) {
|
|
55
61
|
try {
|
|
56
|
-
|
|
62
|
+
const concatted = [];
|
|
63
|
+
(0, index_js_1.bytesConcatTo)(concatted, uint32To(userDefinedItems.length));
|
|
64
|
+
for (const item of userDefinedItems) {
|
|
65
|
+
(0, index_js_1.bytesConcatTo)(concatted, itemCodec.encode(item));
|
|
66
|
+
}
|
|
67
|
+
return (0, index_js_1.bytesFrom)(concatted);
|
|
57
68
|
}
|
|
58
69
|
catch (e) {
|
|
59
70
|
throw new Error(`fixedItemVec(${e?.toString()})`);
|
|
@@ -90,21 +101,17 @@ function dynItemVec(itemCodec) {
|
|
|
90
101
|
return Codec.from({
|
|
91
102
|
encode(userDefinedItems) {
|
|
92
103
|
try {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
offset: 4 + userDefinedItems.length * 4,
|
|
105
|
-
});
|
|
106
|
-
const packedTotalSize = uint32To(encoded.header.byteLength + encoded.body.byteLength + 4);
|
|
107
|
-
return (0, index_js_1.bytesConcat)(packedTotalSize, encoded.header, encoded.body);
|
|
104
|
+
let offset = 4 + userDefinedItems.length * 4;
|
|
105
|
+
const header = [];
|
|
106
|
+
const body = [];
|
|
107
|
+
for (const item of userDefinedItems) {
|
|
108
|
+
const encoded = itemCodec.encode(item);
|
|
109
|
+
(0, index_js_1.bytesConcatTo)(header, uint32To(offset));
|
|
110
|
+
(0, index_js_1.bytesConcatTo)(body, encoded);
|
|
111
|
+
offset += encoded.byteLength;
|
|
112
|
+
}
|
|
113
|
+
const packedTotalSize = uint32To(header.length + body.length + 4);
|
|
114
|
+
return (0, index_js_1.bytesConcat)(packedTotalSize, header, body);
|
|
108
115
|
}
|
|
109
116
|
catch (e) {
|
|
110
117
|
throw new Error(`dynItemVec(${e?.toString()})`);
|
|
@@ -228,26 +235,21 @@ function table(codecLayout) {
|
|
|
228
235
|
const keys = Object.keys(codecLayout);
|
|
229
236
|
return Codec.from({
|
|
230
237
|
encode(object) {
|
|
231
|
-
|
|
232
|
-
const
|
|
238
|
+
let offset = 4 + keys.length * 4;
|
|
239
|
+
const header = [];
|
|
240
|
+
const body = [];
|
|
241
|
+
for (const key of keys) {
|
|
233
242
|
try {
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
body: (0, index_js_1.bytesConcat)(result.body, encodedItem),
|
|
239
|
-
offset: result.offset + (0, index_js_1.bytesFrom)(encodedItem).byteLength,
|
|
240
|
-
};
|
|
243
|
+
const encoded = codecLayout[key].encode(object[key]);
|
|
244
|
+
(0, index_js_1.bytesConcatTo)(header, uint32To(offset));
|
|
245
|
+
(0, index_js_1.bytesConcatTo)(body, encoded);
|
|
246
|
+
offset += encoded.byteLength;
|
|
241
247
|
}
|
|
242
248
|
catch (e) {
|
|
243
249
|
throw new Error(`table.${key}(${e?.toString()})`);
|
|
244
250
|
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
body: (0, index_js_1.bytesFrom)([]),
|
|
248
|
-
offset: headerLength,
|
|
249
|
-
});
|
|
250
|
-
const packedTotalSize = uint32To(header.byteLength + body.byteLength + 4);
|
|
251
|
+
}
|
|
252
|
+
const packedTotalSize = uint32To(header.length + body.length + 4);
|
|
251
253
|
return (0, index_js_1.bytesConcat)(packedTotalSize, header, body);
|
|
252
254
|
},
|
|
253
255
|
decode(buffer) {
|
|
@@ -348,22 +350,26 @@ function union(codecLayout, fields) {
|
|
|
348
350
|
*/
|
|
349
351
|
function struct(codecLayout) {
|
|
350
352
|
const codecArray = Object.values(codecLayout);
|
|
351
|
-
if (codecArray.some((codec) => codec.byteLength === undefined)) {
|
|
352
|
-
throw new Error("struct: all fields must be fixed-size");
|
|
353
|
-
}
|
|
354
353
|
const keys = Object.keys(codecLayout);
|
|
355
354
|
return Codec.from({
|
|
356
|
-
byteLength: codecArray.reduce((
|
|
355
|
+
byteLength: codecArray.reduce((acc, codec) => {
|
|
356
|
+
if (codec.byteLength === undefined) {
|
|
357
|
+
throw new Error("struct: all fields must be fixed-size");
|
|
358
|
+
}
|
|
359
|
+
return acc + codec.byteLength;
|
|
360
|
+
}, 0),
|
|
357
361
|
encode(object) {
|
|
358
|
-
|
|
362
|
+
const bytes = [];
|
|
363
|
+
for (const key of keys) {
|
|
359
364
|
try {
|
|
360
|
-
const
|
|
361
|
-
|
|
365
|
+
const encoded = codecLayout[key].encode(object[key]);
|
|
366
|
+
(0, index_js_1.bytesConcatTo)(bytes, encoded);
|
|
362
367
|
}
|
|
363
368
|
catch (e) {
|
|
364
369
|
throw new Error(`struct.${key}(${e?.toString()})`);
|
|
365
370
|
}
|
|
366
|
-
}
|
|
371
|
+
}
|
|
372
|
+
return (0, index_js_1.bytesFrom)(bytes);
|
|
367
373
|
},
|
|
368
374
|
decode(buffer) {
|
|
369
375
|
const value = (0, index_js_1.bytesFrom)(buffer);
|
|
@@ -399,7 +405,11 @@ function array(itemCodec, itemCount) {
|
|
|
399
405
|
byteLength,
|
|
400
406
|
encode(items) {
|
|
401
407
|
try {
|
|
402
|
-
|
|
408
|
+
const bytes = [];
|
|
409
|
+
for (const item of items) {
|
|
410
|
+
(0, index_js_1.bytesConcatTo)(bytes, itemCodec.encode(item));
|
|
411
|
+
}
|
|
412
|
+
return (0, index_js_1.bytesFrom)(bytes);
|
|
403
413
|
}
|
|
404
414
|
catch (e) {
|
|
405
415
|
throw new Error(`array(${e?.toString()})`);
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { Bytes, BytesLike } from "../bytes/index.js";
|
|
2
2
|
import { Hex } from "../hex/index.js";
|
|
3
|
+
import { Constructor } from "../utils/index.js";
|
|
3
4
|
import { Codec } from "./codec.js";
|
|
4
5
|
/**
|
|
5
|
-
* The base class of CCC to create a serializable instance
|
|
6
|
+
* The base class of CCC to create a serializable instance. This should be used with the {@link codec} decorator.
|
|
6
7
|
* @public
|
|
7
8
|
*/
|
|
8
9
|
export declare abstract class Entity {
|
|
10
|
+
/**
|
|
11
|
+
* Generate a base class of CCC to create a serializable instance.
|
|
12
|
+
* This should be used with the {@link codec} decorator.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
9
15
|
static Base<SubTypeLike, SubType = SubTypeLike>(): (abstract new () => {
|
|
10
16
|
/**
|
|
11
17
|
* Convert the entity to bytes
|
|
@@ -25,7 +31,7 @@ export declare abstract class Entity {
|
|
|
25
31
|
* @param other - The other entity to compare with
|
|
26
32
|
* @returns True if the entities are equal, false otherwise
|
|
27
33
|
*/
|
|
28
|
-
eq(other: SubTypeLike
|
|
34
|
+
eq(other: SubTypeLike): boolean;
|
|
29
35
|
/**
|
|
30
36
|
* Calculate the hash of the entity
|
|
31
37
|
* @public
|
|
@@ -80,8 +86,23 @@ export declare abstract class Entity {
|
|
|
80
86
|
abstract hash(): Hex;
|
|
81
87
|
abstract clone(): Entity;
|
|
82
88
|
}
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
/**
|
|
90
|
+
* A class decorator to add methods implementation on the {@link Entity.Base} class
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* @mol.codec(
|
|
94
|
+
* mol.table({
|
|
95
|
+
* codeHash: mol.Byte32,
|
|
96
|
+
* hashType: HashTypeCodec,
|
|
97
|
+
* args: mol.Bytes,
|
|
98
|
+
* }),
|
|
99
|
+
* )
|
|
100
|
+
* export class Script extends mol.Entity.Base<ScriptLike, Script>() {
|
|
101
|
+
* from(scriptLike: ScriptLike): Script {}
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function codec<Encodable, TypeLike extends Encodable, Decoded extends TypeLike, Type extends object & TypeLike, ConstructorType extends Constructor<Type> & {
|
|
85
106
|
from(decoded: TypeLike): Type;
|
|
86
107
|
byteLength?: number;
|
|
87
108
|
encode(encodable: TypeLike): Bytes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../src/molecule/entity.ts"],"names":[],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zB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CACnB,SAAS,EACT,QAAQ,SAAS,SAAS,EAC1B,OAAO,SAAS,QAAQ,EACxB,IAAI,SAAS,MAAM,GAAG,QAAQ,EAC9B,eAAe,SAAS,WAAW,CAAC,IAAI,CAAC,GAAG;IAC1C,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,SAAS,EAAE,QAAQ,GAAG,KAAK,CAAC;IACnC,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,QAAQ,CAAC;IACvC,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACnC,EACD,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,iBACF,eAAe;;;sBAGhB,QAAQ,GAAG,KAAK;sBAGhB,SAAS,GAAG,IAAI;qBAIjB,SAAS,GAAG,IAAI;kBAjB5B,QAAQ,GAAG,IAAI;oBAsBhC"}
|
|
@@ -5,10 +5,15 @@ exports.codec = codec;
|
|
|
5
5
|
const index_js_1 = require("../bytes/index.js");
|
|
6
6
|
const index_js_2 = require("../hasher/index.js");
|
|
7
7
|
/**
|
|
8
|
-
* The base class of CCC to create a serializable instance
|
|
8
|
+
* The base class of CCC to create a serializable instance. This should be used with the {@link codec} decorator.
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
11
|
class Entity {
|
|
12
|
+
/**
|
|
13
|
+
* Generate a base class of CCC to create a serializable instance.
|
|
14
|
+
* This should be used with the {@link codec} decorator.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
12
17
|
static Base() {
|
|
13
18
|
class Impl {
|
|
14
19
|
/**
|
|
@@ -98,6 +103,22 @@ class Entity {
|
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
105
|
exports.Entity = Entity;
|
|
106
|
+
/**
|
|
107
|
+
* A class decorator to add methods implementation on the {@link Entity.Base} class
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* @mol.codec(
|
|
111
|
+
* mol.table({
|
|
112
|
+
* codeHash: mol.Byte32,
|
|
113
|
+
* hashType: HashTypeCodec,
|
|
114
|
+
* args: mol.Bytes,
|
|
115
|
+
* }),
|
|
116
|
+
* )
|
|
117
|
+
* export class Script extends mol.Entity.Base<ScriptLike, Script>() {
|
|
118
|
+
* from(scriptLike: ScriptLike): Script {}
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
101
122
|
function codec(codec) {
|
|
102
123
|
return function (Constructor) {
|
|
103
124
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/num/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,iBAAiB,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AAEzB;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,GAAG,GAAG,CAS7D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,GAAG,GAAG,CAS7D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAUzC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAE1C;AAED;;;;;;;;;;;;GAYG;AAEH,wBA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AAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAEhE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAOhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAEhD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAElD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAElD"}
|
|
@@ -143,7 +143,7 @@ function numBeToBytes(val, bytes) {
|
|
|
143
143
|
if (bytes == null) {
|
|
144
144
|
return rawBytes;
|
|
145
145
|
}
|
|
146
|
-
return (0, index_js_1.bytesConcat)(
|
|
146
|
+
return (0, index_js_1.bytesConcat)("00".repeat(bytes - rawBytes.length), rawBytes);
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
149
|
* Converts a byte array to a Num (bigint) assuming little-endian order.
|
|
@@ -173,7 +173,7 @@ function numFromBytes(val) {
|
|
|
173
173
|
* ```
|
|
174
174
|
*/
|
|
175
175
|
function numLeFromBytes(val) {
|
|
176
|
-
return numBeFromBytes(
|
|
176
|
+
return numBeFromBytes((0, index_js_1.bytesFrom)(val).reverse());
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
179
|
* Converts a byte array to a Num (bigint) assuming big-endian order.
|
|
@@ -37,6 +37,6 @@ function btcPublicKeyFromP2pkhAddress(address) {
|
|
|
37
37
|
*/
|
|
38
38
|
function verifyMessageBtcEcdsa(message, signature, publicKey) {
|
|
39
39
|
const challenge = typeof message === "string" ? message : (0, index_js_2.hexFrom)(message).slice(2);
|
|
40
|
-
const
|
|
40
|
+
const rawSign = (0, index_js_1.bytesFrom)(signature, "base64").slice(1);
|
|
41
41
|
return secp256k1_1.secp256k1.verify((0, index_js_1.bytesFrom)(rawSign), (0, bitcoinjs_message_1.magicHash)(challenge), publicKey);
|
|
42
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/signer/doge/verify.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAO5D;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/signer/doge/verify.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAO5D;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAuBT"}
|
|
@@ -11,7 +11,9 @@ const verify_js_1 = require("../btc/verify.js");
|
|
|
11
11
|
*/
|
|
12
12
|
function verifyMessageDogeEcdsa(message, signature, address) {
|
|
13
13
|
const challenge = typeof message === "string" ? message : (0, index_js_2.hexFrom)(message).slice(2);
|
|
14
|
-
const
|
|
14
|
+
const signatureBytes = (0, index_js_1.bytesFrom)(signature, "base64");
|
|
15
|
+
const recoveryBit = signatureBytes[0];
|
|
16
|
+
const rawSign = signatureBytes.slice(1);
|
|
15
17
|
const sig = secp256k1_1.secp256k1.Signature.fromCompact((0, index_js_2.hexFrom)(rawSign).slice(2)).addRecoveryBit(recoveryBit - 31);
|
|
16
18
|
return ((0, verify_js_1.btcPublicKeyFromP2pkhAddress)(address) ===
|
|
17
19
|
(0, index_js_2.hexFrom)((0, verify_js_1.btcEcdsaPublicKeyHash)(sig
|
package/package.json
CHANGED
|
@@ -29,7 +29,9 @@ export function addressPayloadFromString(address: string): {
|
|
|
29
29
|
// Try parse full format address
|
|
30
30
|
try {
|
|
31
31
|
const { words, prefix } = bech32m.decode(address, ADDRESS_BECH32_LIMIT);
|
|
32
|
-
const
|
|
32
|
+
const decoded = bech32m.fromWords(words);
|
|
33
|
+
const formatType = decoded[0];
|
|
34
|
+
const payload = decoded.slice(1);
|
|
33
35
|
|
|
34
36
|
if (formatType === (AddressFormat.Full as number)) {
|
|
35
37
|
return { prefix, format: AddressFormat.Full, payload };
|
|
@@ -39,7 +41,9 @@ export function addressPayloadFromString(address: string): {
|
|
|
39
41
|
// Try parse legacy 2019 format address
|
|
40
42
|
try {
|
|
41
43
|
const { prefix, words } = bech32.decode(address, ADDRESS_BECH32_LIMIT);
|
|
42
|
-
const
|
|
44
|
+
const decoded = bech32.fromWords(words);
|
|
45
|
+
const formatType = decoded[0];
|
|
46
|
+
const payload = decoded.slice(1);
|
|
43
47
|
if (
|
|
44
48
|
[
|
|
45
49
|
AddressFormat.FullData,
|