@ckb-ccc/core 0.0.10-alpha.0 → 0.0.10-alpha.5
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/dist/ckb/transaction.d.ts +19 -15
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +44 -11
- package/dist/client/client.d.ts +1 -1
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +30 -2
- package/dist/client/clientPublicTestnet.advanced.js +3 -3
- package/dist/client/clientTypes.advanced.d.ts +8 -8
- package/dist/client/clientTypes.advanced.d.ts.map +1 -1
- package/dist/client/clientTypes.d.ts +2 -2
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/clientTypes.js +2 -2
- package/dist/signer/ckb/index.d.ts +2 -0
- package/dist/signer/ckb/index.d.ts.map +1 -1
- package/dist/signer/ckb/index.js +2 -0
- package/dist/signer/ckb/signerCkbPrivateKey.d.ts +4 -13
- package/dist/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -1
- package/dist/signer/ckb/signerCkbPrivateKey.js +10 -37
- package/dist/signer/ckb/signerCkbPublicKey.d.ts +18 -0
- package/dist/signer/ckb/signerCkbPublicKey.d.ts.map +1 -0
- package/dist/signer/ckb/signerCkbPublicKey.js +44 -0
- package/dist/signer/ckb/verifyCkbSecp256k1.d.ts +5 -0
- package/dist/signer/ckb/verifyCkbSecp256k1.d.ts.map +1 -0
- package/dist/signer/ckb/verifyCkbSecp256k1.js +14 -0
- package/dist/signer/signer/index.d.ts.map +1 -1
- package/dist/signer/signer/index.js +2 -0
- package/dist/utils/index.d.ts +18 -9
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -2
- package/dist.commonjs/ckb/transaction.d.ts +19 -15
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +43 -10
- package/dist.commonjs/client/client.d.ts +1 -1
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +30 -2
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +3 -3
- package/dist.commonjs/client/clientTypes.advanced.d.ts +8 -8
- package/dist.commonjs/client/clientTypes.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientTypes.d.ts +2 -2
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
- package/dist.commonjs/client/clientTypes.js +2 -2
- package/dist.commonjs/signer/ckb/index.d.ts +2 -0
- package/dist.commonjs/signer/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/index.js +2 -0
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts +4 -13
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +10 -37
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts +18 -0
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +48 -0
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts +5 -0
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +19 -0
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/signer/index.js +2 -0
- package/dist.commonjs/utils/index.d.ts +18 -9
- package/dist.commonjs/utils/index.d.ts.map +1 -1
- package/dist.commonjs/utils/index.js +2 -2
- package/package.json +3 -3
- package/src/ckb/transaction.ts +87 -33
- package/src/client/client.ts +1 -1
- package/src/client/clientPublicMainnet.advanced.ts +34 -2
- package/src/client/clientPublicTestnet.advanced.ts +3 -3
- package/src/client/clientTypes.advanced.ts +8 -8
- package/src/client/clientTypes.ts +4 -4
- package/src/signer/ckb/index.ts +2 -0
- package/src/signer/ckb/signerCkbPrivateKey.ts +14 -54
- package/src/signer/ckb/signerCkbPublicKey.ts +63 -0
- package/src/signer/ckb/verifyCkbSecp256k1.ts +27 -0
- package/src/signer/signer/index.ts +6 -0
- package/src/utils/index.ts +24 -12
|
@@ -2,56 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SignerCkbPrivateKey = void 0;
|
|
4
4
|
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
5
|
-
const address_1 = require("../../address");
|
|
6
5
|
const bytes_1 = require("../../bytes");
|
|
7
6
|
const ckb_1 = require("../../ckb");
|
|
8
|
-
const client_1 = require("../../client");
|
|
9
7
|
const hasher_1 = require("../../hasher");
|
|
10
8
|
const hex_1 = require("../../hex");
|
|
11
9
|
const num_1 = require("../../num");
|
|
12
|
-
const
|
|
13
|
-
class SignerCkbPrivateKey extends
|
|
14
|
-
get type() {
|
|
15
|
-
return signer_1.SignerType.CKB;
|
|
16
|
-
}
|
|
17
|
-
get signType() {
|
|
18
|
-
return signer_1.SignerSignType.CkbSecp256k1;
|
|
19
|
-
}
|
|
10
|
+
const signerCkbPublicKey_1 = require("./signerCkbPublicKey");
|
|
11
|
+
class SignerCkbPrivateKey extends signerCkbPublicKey_1.SignerCkbPublicKey {
|
|
20
12
|
constructor(client, privateKey) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if ((0, bytes_1.bytesFrom)(this.privateKey).length !== 32) {
|
|
13
|
+
const pk = (0, hex_1.hexFrom)(privateKey);
|
|
14
|
+
if ((0, bytes_1.bytesFrom)(pk).length !== 32) {
|
|
24
15
|
throw new Error("Private key must be 32 bytes!");
|
|
25
16
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
async isConnected() {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
async getInternalAddress() {
|
|
32
|
-
return this.getRecommendedAddress();
|
|
33
|
-
}
|
|
34
|
-
async getAddressObjs() {
|
|
35
|
-
const publicKey = this.getPublicKey();
|
|
36
|
-
return [
|
|
37
|
-
await address_1.Address.fromKnownScript(this.client, client_1.KnownScript.Secp256k1Blake160, (0, bytes_1.bytesFrom)((0, hasher_1.hashCkb)(publicKey)).slice(0, 20)),
|
|
38
|
-
];
|
|
17
|
+
super(client, secp256k1_1.secp256k1.getPublicKey((0, bytes_1.bytesFrom)(pk), true));
|
|
18
|
+
this.privateKey = pk;
|
|
39
19
|
}
|
|
40
20
|
async signMessageRaw(message) {
|
|
41
|
-
const
|
|
21
|
+
const msg = typeof message === "string" ? message : (0, hex_1.hexFrom)(message);
|
|
22
|
+
const buffer = (0, bytes_1.bytesFrom)(`Nervos Message:${msg}`, "utf8");
|
|
23
|
+
const hash = (0, hasher_1.hashCkb)(buffer);
|
|
24
|
+
const signature = secp256k1_1.secp256k1.sign((0, bytes_1.bytesFrom)(hash), (0, bytes_1.bytesFrom)(this.privateKey));
|
|
42
25
|
const { r, s, recovery } = signature;
|
|
43
26
|
return (0, hex_1.hexFrom)((0, bytes_1.bytesConcat)((0, num_1.numBeToBytes)(r, 32), (0, num_1.numBeToBytes)(s, 32), (0, num_1.numBeToBytes)(recovery, 1)));
|
|
44
27
|
}
|
|
45
|
-
getPublicKey() {
|
|
46
|
-
return secp256k1_1.secp256k1.getPublicKey((0, bytes_1.bytesFrom)(this.privateKey), true);
|
|
47
|
-
}
|
|
48
|
-
async prepareTransaction(txLike) {
|
|
49
|
-
const tx = ckb_1.Transaction.from(txLike);
|
|
50
|
-
const { script } = await this.getRecommendedAddressObj();
|
|
51
|
-
await tx.addCellDepsOfKnownScripts(this.client, client_1.KnownScript.Secp256k1Blake160);
|
|
52
|
-
await tx.prepareSighashAllWitness(script, 65, this.client);
|
|
53
|
-
return tx;
|
|
54
|
-
}
|
|
55
28
|
async signOnlyTransaction(txLike) {
|
|
56
29
|
const tx = ckb_1.Transaction.from(txLike);
|
|
57
30
|
const { script } = await this.getRecommendedAddressObj();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Address } from "../../address";
|
|
2
|
+
import { Transaction, TransactionLike } from "../../ckb";
|
|
3
|
+
import { Client } from "../../client";
|
|
4
|
+
import { Hex, HexLike } from "../../hex";
|
|
5
|
+
import { Signer, SignerSignType, SignerType } from "../signer";
|
|
6
|
+
export declare class SignerCkbPublicKey extends Signer {
|
|
7
|
+
get type(): SignerType;
|
|
8
|
+
get signType(): SignerSignType;
|
|
9
|
+
readonly publicKey: Hex;
|
|
10
|
+
constructor(client: Client, publicKey: HexLike);
|
|
11
|
+
connect(): Promise<void>;
|
|
12
|
+
isConnected(): Promise<boolean>;
|
|
13
|
+
getInternalAddress(): Promise<string>;
|
|
14
|
+
getIdentity(): Promise<string>;
|
|
15
|
+
getAddressObjs(): Promise<Address[]>;
|
|
16
|
+
prepareTransaction(txLike: TransactionLike): Promise<Transaction>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=signerCkbPublicKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signerCkbPublicKey.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/signerCkbPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,MAAM,EAAe,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/D,qBAAa,kBAAmB,SAAQ,MAAM;IAC5C,IAAI,IAAI,IAAI,UAAU,CAErB;IAED,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED,SAAgB,SAAS,EAAE,GAAG,CAAC;gBAEnB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO;IASxC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAExB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAUpC,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAUxE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerCkbPublicKey = void 0;
|
|
4
|
+
const address_1 = require("../../address");
|
|
5
|
+
const bytes_1 = require("../../bytes");
|
|
6
|
+
const ckb_1 = require("../../ckb");
|
|
7
|
+
const client_1 = require("../../client");
|
|
8
|
+
const hasher_1 = require("../../hasher");
|
|
9
|
+
const hex_1 = require("../../hex");
|
|
10
|
+
const signer_1 = require("../signer");
|
|
11
|
+
class SignerCkbPublicKey extends signer_1.Signer {
|
|
12
|
+
get type() {
|
|
13
|
+
return signer_1.SignerType.CKB;
|
|
14
|
+
}
|
|
15
|
+
get signType() {
|
|
16
|
+
return signer_1.SignerSignType.CkbSecp256k1;
|
|
17
|
+
}
|
|
18
|
+
constructor(client, publicKey) {
|
|
19
|
+
super(client);
|
|
20
|
+
this.publicKey = (0, hex_1.hexFrom)(publicKey);
|
|
21
|
+
if ((0, bytes_1.bytesFrom)(this.publicKey).length !== 33) {
|
|
22
|
+
throw new Error("Public key must be 33 bytes!");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async connect() { }
|
|
26
|
+
async isConnected() {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
async getInternalAddress() {
|
|
30
|
+
return this.getRecommendedAddress();
|
|
31
|
+
}
|
|
32
|
+
async getIdentity() {
|
|
33
|
+
return this.publicKey;
|
|
34
|
+
}
|
|
35
|
+
async getAddressObjs() {
|
|
36
|
+
return [
|
|
37
|
+
await address_1.Address.fromKnownScript(this.client, client_1.KnownScript.Secp256k1Blake160, (0, bytes_1.bytesFrom)((0, hasher_1.hashCkb)(this.publicKey)).slice(0, 20)),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
async prepareTransaction(txLike) {
|
|
41
|
+
const tx = ckb_1.Transaction.from(txLike);
|
|
42
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
43
|
+
await tx.addCellDepsOfKnownScripts(this.client, client_1.KnownScript.Secp256k1Blake160);
|
|
44
|
+
await tx.prepareSighashAllWitness(script, 65, this.client);
|
|
45
|
+
return tx;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.SignerCkbPublicKey = SignerCkbPublicKey;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BytesLike } from "../../bytes";
|
|
2
|
+
import { Hex } from "../../hex";
|
|
3
|
+
export declare function messageHashCkbSecp256k1(message: string | BytesLike): Hex;
|
|
4
|
+
export declare function verifyMessageCkbSecp256k1(message: string | BytesLike, signature: string, publicKey: string): boolean;
|
|
5
|
+
//# sourceMappingURL=verifyCkbSecp256k1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifyCkbSecp256k1.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/verifyCkbSecp256k1.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAa,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,GAAG,EAAW,MAAM,WAAW,CAAC;AAGzC,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,GAAG,CAIxE;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAUT"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyMessageCkbSecp256k1 = exports.messageHashCkbSecp256k1 = void 0;
|
|
4
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
5
|
+
const bytes_1 = require("../../bytes");
|
|
6
|
+
const hasher_1 = require("../../hasher");
|
|
7
|
+
const hex_1 = require("../../hex");
|
|
8
|
+
const num_1 = require("../../num");
|
|
9
|
+
function messageHashCkbSecp256k1(message) {
|
|
10
|
+
const msg = typeof message === "string" ? message : (0, hex_1.hexFrom)(message);
|
|
11
|
+
const buffer = (0, bytes_1.bytesFrom)(`Nervos Message:${msg}`, "utf8");
|
|
12
|
+
return (0, hasher_1.hashCkb)(buffer);
|
|
13
|
+
}
|
|
14
|
+
exports.messageHashCkbSecp256k1 = messageHashCkbSecp256k1;
|
|
15
|
+
function verifyMessageCkbSecp256k1(message, signature, publicKey) {
|
|
16
|
+
const signatureBytes = (0, bytes_1.bytesFrom)(signature);
|
|
17
|
+
return secp256k1_1.secp256k1.verify(new secp256k1_1.secp256k1.Signature((0, num_1.numFrom)(signatureBytes.slice(0, 32)), (0, num_1.numFrom)(signatureBytes.slice(32, 64))).addRecoveryBit(Number((0, num_1.numFrom)(signatureBytes.slice(64, 65)))), (0, bytes_1.bytesFrom)(messageHashCkbSecp256k1(message)), (0, bytes_1.bytesFrom)(publicKey));
|
|
18
|
+
}
|
|
19
|
+
exports.verifyMessageCkbSecp256k1 = verifyMessageCkbSecp256k1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/signer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACzD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;;;;;;;OAOG;IACG,aAAa,CACjB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,GAC5B,OAAO,CAAC,OAAO,CAAC;IAenB;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAItE;;;;;OAKG;IACG,eAAe,CAAC,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC;IAIxD;;;;;OAKG;IACG,eAAe,CAAC,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAKhE;;;;;;OAMG;IACH,kBAAkB,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAI5D;;;;;;OAMG;IACH,mBAAmB,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAG9D;AAED;;GAEG;AACH,qBAAa,UAAU;IAEZ,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;gBADd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;CAExB;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SignerInfo = exports.Signer = exports.Signature = exports.SignerType = exports.SignerSignType = void 0;
|
|
4
4
|
const btc_1 = require("../btc");
|
|
5
|
+
const verifyCkbSecp256k1_1 = require("../ckb/verifyCkbSecp256k1");
|
|
5
6
|
const verifyJoyId_1 = require("../ckb/verifyJoyId");
|
|
6
7
|
const verify_1 = require("../evm/verify");
|
|
7
8
|
const verify_2 = require("../nostr/verify");
|
|
@@ -66,6 +67,7 @@ class Signer {
|
|
|
66
67
|
case SignerSignType.NostrEvent:
|
|
67
68
|
return (0, verify_2.verifyMessageNostrEvent)(message, signature.signature, signature.identity);
|
|
68
69
|
case SignerSignType.CkbSecp256k1:
|
|
70
|
+
return (0, verifyCkbSecp256k1_1.verifyMessageCkbSecp256k1)(message, signature.signature, signature.identity);
|
|
69
71
|
case SignerSignType.Unknown:
|
|
70
72
|
throw new Error("Unknown signer sign type");
|
|
71
73
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param transformer - The transformer.
|
|
5
5
|
* @param value - The value to be transformed.
|
|
6
|
-
* @returns If the value is empty, it
|
|
6
|
+
* @returns If the value is empty, it becomes undefined. Otherwise it will be transformed.
|
|
7
7
|
*/
|
|
8
8
|
export declare function apply<T, R>(transformer: (val: T) => R, value: undefined): undefined;
|
|
9
9
|
/**
|
|
@@ -11,15 +11,15 @@ export declare function apply<T, R>(transformer: (val: T) => R, value: undefined
|
|
|
11
11
|
*
|
|
12
12
|
* @param transformer - The transformer.
|
|
13
13
|
* @param value - The value to be transformed.
|
|
14
|
-
* @returns If the value is empty, it
|
|
14
|
+
* @returns If the value is empty, it becomes undefined. Otherwise it will be transformed.
|
|
15
15
|
*/
|
|
16
|
-
export declare function apply<T, R>(transformer: (val: T) => R, value: null):
|
|
16
|
+
export declare function apply<T, R>(transformer: (val: T) => R, value: null): undefined;
|
|
17
17
|
/**
|
|
18
18
|
* A type safe way to apply a transformer on a value if it's not empty.
|
|
19
19
|
*
|
|
20
20
|
* @param transformer - The transformer.
|
|
21
21
|
* @param value - The value to be transformed.
|
|
22
|
-
* @returns If the value is empty, it
|
|
22
|
+
* @returns If the value is empty, it becomes undefined. Otherwise it will be transformed.
|
|
23
23
|
*/
|
|
24
24
|
export declare function apply<T, R>(transformer: (val: T) => R, value: T): R;
|
|
25
25
|
/**
|
|
@@ -27,7 +27,7 @@ export declare function apply<T, R>(transformer: (val: T) => R, value: T): R;
|
|
|
27
27
|
*
|
|
28
28
|
* @param transformer - The transformer.
|
|
29
29
|
* @param value - The value to be transformed.
|
|
30
|
-
* @returns If the value is empty, it
|
|
30
|
+
* @returns If the value is empty, it becomes undefined. Otherwise it will be transformed.
|
|
31
31
|
*/
|
|
32
32
|
export declare function apply<T, R>(transformer: (val: T) => R, value: T | undefined): R | undefined;
|
|
33
33
|
/**
|
|
@@ -35,17 +35,26 @@ export declare function apply<T, R>(transformer: (val: T) => R, value: T | undef
|
|
|
35
35
|
*
|
|
36
36
|
* @param transformer - The transformer.
|
|
37
37
|
* @param value - The value to be transformed.
|
|
38
|
-
* @returns If the value is empty, it
|
|
38
|
+
* @returns If the value is empty, it becomes undefined. Otherwise it will be transformed.
|
|
39
39
|
*/
|
|
40
|
-
export declare function apply<T, R>(transformer: (val: T) => R, value: T | null): R |
|
|
40
|
+
export declare function apply<T, R>(transformer: (val: T) => R, value: T | null): R | undefined;
|
|
41
41
|
/**
|
|
42
42
|
* A type safe way to apply a transformer on a value if it's not empty.
|
|
43
43
|
*
|
|
44
44
|
* @param transformer - The transformer.
|
|
45
45
|
* @param value - The value to be transformed.
|
|
46
|
-
* @returns If the value is empty, it
|
|
46
|
+
* @returns If the value is empty, it becomes undefined. Otherwise it will be transformed.
|
|
47
47
|
*/
|
|
48
|
-
export declare function apply<T, R>(transformer: (val: T) => R, value: undefined | null): undefined
|
|
48
|
+
export declare function apply<T, R>(transformer: (val: T) => R, value: undefined | null): undefined;
|
|
49
|
+
/**
|
|
50
|
+
/**
|
|
51
|
+
* A type safe way to apply a transformer on a value if it's not empty.
|
|
52
|
+
*
|
|
53
|
+
* @param transformer - The transformer.
|
|
54
|
+
* @param value - The value to be transformed.
|
|
55
|
+
* @returns If the value is empty, it becomes undefined. Otherwise it will be transformed.
|
|
56
|
+
*/
|
|
57
|
+
export declare function apply<T, R>(transformer: (val: T) => R, value: T | undefined | null): R | undefined;
|
|
49
58
|
/**
|
|
50
59
|
* Similar to Array.reduce, but the accumulator can returns Promise.
|
|
51
60
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,SAAS,GACf,SAAS,CAAC;AACb;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,SAAS,GACf,SAAS,CAAC;AACb;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,SAAS,CAAC;AAChF;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;AACrE;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,CAAC,GAAG,SAAS,GACnB,CAAC,GAAG,SAAS,CAAC;AACjB;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EA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exports.apply = void 0;
|
|
|
6
6
|
*
|
|
7
7
|
* @param transformer - The transformer.
|
|
8
8
|
* @param value - The value to be transformed.
|
|
9
|
-
* @returns If the value is empty, it
|
|
9
|
+
* @returns If the value is empty, it becomes undefined. Otherwise it will be transformed.
|
|
10
10
|
*/
|
|
11
11
|
function apply(transformer, value) {
|
|
12
12
|
if (value == null) {
|
|
13
|
-
return
|
|
13
|
+
return undefined;
|
|
14
14
|
}
|
|
15
15
|
return transformer(value);
|
|
16
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/core",
|
|
3
|
-
"version": "0.0.10-alpha.
|
|
3
|
+
"version": "0.0.10-alpha.5",
|
|
4
4
|
"description": "Core of CCC - CKBer's Codebase",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@ckb-lumos/helpers": "^0.22.2",
|
|
60
|
-
"@joyid/ckb": "^
|
|
60
|
+
"@joyid/ckb": "^1.0.1",
|
|
61
61
|
"@noble/curves": "^1.4.2",
|
|
62
62
|
"@noble/hashes": "^1.4.0",
|
|
63
63
|
"abort-controller": "^3.0.0",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"cross-fetch": "^4.0.0",
|
|
69
69
|
"ethers": "^6.13.1"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "40a3d50aa3697a98c7ac711cd526ef322ccad760"
|
|
72
72
|
}
|
package/src/ckb/transaction.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { TransactionSkeletonType } from "@ckb-lumos/helpers";
|
|
|
2
2
|
import { ClientCollectableSearchKeyFilterLike } from "../advancedBarrel";
|
|
3
3
|
import { Bytes, BytesLike, bytesFrom } from "../bytes";
|
|
4
4
|
import { CellDepInfoLike, Client, KnownScript } from "../client";
|
|
5
|
-
import { Zero, fixedPointFrom } from "../fixedPoint";
|
|
5
|
+
import { Zero, fixedPointFrom, fixedPointToString } from "../fixedPoint";
|
|
6
6
|
import { Hasher, hashCkb } from "../hasher";
|
|
7
7
|
import { Hex, HexLike, hexFrom } from "../hex";
|
|
8
8
|
import {
|
|
@@ -210,7 +210,7 @@ export class OutPoint {
|
|
|
210
210
|
export type CellOutputLike = {
|
|
211
211
|
capacity: NumLike;
|
|
212
212
|
lock: ScriptLike;
|
|
213
|
-
type?: ScriptLike;
|
|
213
|
+
type?: ScriptLike | null;
|
|
214
214
|
};
|
|
215
215
|
export class CellOutput {
|
|
216
216
|
/**
|
|
@@ -387,9 +387,9 @@ export class Cell {
|
|
|
387
387
|
|
|
388
388
|
export type CellInputLike = {
|
|
389
389
|
previousOutput: OutPointLike;
|
|
390
|
-
since?: NumLike;
|
|
391
|
-
cellOutput?: CellOutputLike;
|
|
392
|
-
outputData?: HexLike;
|
|
390
|
+
since?: NumLike | null;
|
|
391
|
+
cellOutput?: CellOutputLike | null;
|
|
392
|
+
outputData?: HexLike | null;
|
|
393
393
|
};
|
|
394
394
|
export class CellInput {
|
|
395
395
|
/**
|
|
@@ -659,9 +659,9 @@ export class CellDep {
|
|
|
659
659
|
}
|
|
660
660
|
|
|
661
661
|
export type WitnessArgsLike = {
|
|
662
|
-
lock?: HexLike;
|
|
663
|
-
inputType?: HexLike;
|
|
664
|
-
outputType?: HexLike;
|
|
662
|
+
lock?: HexLike | null;
|
|
663
|
+
inputType?: HexLike | null;
|
|
664
|
+
outputType?: HexLike | null;
|
|
665
665
|
};
|
|
666
666
|
export class WitnessArgs {
|
|
667
667
|
/**
|
|
@@ -771,14 +771,16 @@ export function udtBalanceFrom(dataLike: BytesLike) {
|
|
|
771
771
|
}
|
|
772
772
|
|
|
773
773
|
export type TransactionLike = {
|
|
774
|
-
version?: NumLike;
|
|
775
|
-
cellDeps?: CellDepLike[];
|
|
776
|
-
headerDeps?: HexLike[];
|
|
777
|
-
inputs?: CellInputLike[];
|
|
778
|
-
outputs?:
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
774
|
+
version?: NumLike | null;
|
|
775
|
+
cellDeps?: CellDepLike[] | null;
|
|
776
|
+
headerDeps?: HexLike[] | null;
|
|
777
|
+
inputs?: CellInputLike[] | null;
|
|
778
|
+
outputs?:
|
|
779
|
+
| (Omit<CellOutputLike, "capacity"> &
|
|
780
|
+
Partial<Pick<CellOutputLike, "capacity">>)[]
|
|
781
|
+
| null;
|
|
782
|
+
outputsData?: HexLike[] | null;
|
|
783
|
+
witnesses?: HexLike[] | null;
|
|
782
784
|
};
|
|
783
785
|
export class Transaction {
|
|
784
786
|
/**
|
|
@@ -899,10 +901,7 @@ export class Transaction {
|
|
|
899
901
|
const outputsData = outputs.map((_, i) =>
|
|
900
902
|
hexFrom(tx.outputsData?.[i] ?? "0x"),
|
|
901
903
|
);
|
|
902
|
-
if (
|
|
903
|
-
tx.outputsData !== undefined &&
|
|
904
|
-
outputsData.length < tx.outputsData.length
|
|
905
|
-
) {
|
|
904
|
+
if (tx.outputsData != null && outputsData.length < tx.outputsData.length) {
|
|
906
905
|
outputsData.push(
|
|
907
906
|
...tx.outputsData.slice(outputsData.length).map((d) => hexFrom(d)),
|
|
908
907
|
);
|
|
@@ -1418,7 +1417,10 @@ export class Transaction {
|
|
|
1418
1417
|
array: Cell[],
|
|
1419
1418
|
) => Promise<T | undefined> | T | undefined,
|
|
1420
1419
|
init: T,
|
|
1421
|
-
): Promise<
|
|
1420
|
+
): Promise<{
|
|
1421
|
+
addedCount: number;
|
|
1422
|
+
accumulated?: T;
|
|
1423
|
+
}> {
|
|
1422
1424
|
const scripts = (await from.getAddressObjs()).map(({ script }) => script);
|
|
1423
1425
|
const collectedCells = [];
|
|
1424
1426
|
let acc: T = init;
|
|
@@ -1453,13 +1455,18 @@ export class Transaction {
|
|
|
1453
1455
|
}),
|
|
1454
1456
|
),
|
|
1455
1457
|
);
|
|
1456
|
-
return
|
|
1458
|
+
return {
|
|
1459
|
+
addedCount: collectedCells.length,
|
|
1460
|
+
};
|
|
1457
1461
|
}
|
|
1458
1462
|
acc = next;
|
|
1459
1463
|
}
|
|
1460
1464
|
}
|
|
1461
1465
|
|
|
1462
|
-
|
|
1466
|
+
return {
|
|
1467
|
+
addedCount: collectedCells.length,
|
|
1468
|
+
accumulated: acc,
|
|
1469
|
+
};
|
|
1463
1470
|
}
|
|
1464
1471
|
|
|
1465
1472
|
async completeInputsByCapacity(
|
|
@@ -1474,7 +1481,7 @@ export class Transaction {
|
|
|
1474
1481
|
return 0;
|
|
1475
1482
|
}
|
|
1476
1483
|
|
|
1477
|
-
|
|
1484
|
+
const { addedCount, accumulated } = await this.completeInputs(
|
|
1478
1485
|
from,
|
|
1479
1486
|
filter ?? {
|
|
1480
1487
|
scriptLenRange: [0, 1],
|
|
@@ -1482,10 +1489,35 @@ export class Transaction {
|
|
|
1482
1489
|
},
|
|
1483
1490
|
(acc, { cellOutput: { capacity } }) => {
|
|
1484
1491
|
const sum = acc + capacity;
|
|
1485
|
-
return sum
|
|
1492
|
+
return sum >= exceptedCapacity ? undefined : sum;
|
|
1486
1493
|
},
|
|
1487
1494
|
inputsCapacity,
|
|
1488
1495
|
);
|
|
1496
|
+
|
|
1497
|
+
if (accumulated === undefined) {
|
|
1498
|
+
return addedCount;
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
throw new Error(
|
|
1502
|
+
`Insufficient CKB, need ${fixedPointToString(exceptedCapacity - accumulated)} extra CKB`,
|
|
1503
|
+
);
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
async completeInputsAll(
|
|
1507
|
+
from: Signer,
|
|
1508
|
+
filter?: ClientCollectableSearchKeyFilterLike,
|
|
1509
|
+
): Promise<number> {
|
|
1510
|
+
const { addedCount } = await this.completeInputs(
|
|
1511
|
+
from,
|
|
1512
|
+
filter ?? {
|
|
1513
|
+
scriptLenRange: [0, 1],
|
|
1514
|
+
outputDataLenRange: [0, 1],
|
|
1515
|
+
},
|
|
1516
|
+
(acc, { cellOutput: { capacity } }) => acc + capacity,
|
|
1517
|
+
Zero,
|
|
1518
|
+
);
|
|
1519
|
+
|
|
1520
|
+
return addedCount;
|
|
1489
1521
|
}
|
|
1490
1522
|
|
|
1491
1523
|
async completeInputsByUdt(from: Signer, type: ScriptLike): Promise<number> {
|
|
@@ -1495,7 +1527,7 @@ export class Transaction {
|
|
|
1495
1527
|
return 0;
|
|
1496
1528
|
}
|
|
1497
1529
|
|
|
1498
|
-
|
|
1530
|
+
const { addedCount, accumulated } = await this.completeInputs(
|
|
1499
1531
|
from,
|
|
1500
1532
|
{
|
|
1501
1533
|
script: type,
|
|
@@ -1504,10 +1536,18 @@ export class Transaction {
|
|
|
1504
1536
|
(acc, { outputData }) => {
|
|
1505
1537
|
const balance = udtBalanceFrom(outputData);
|
|
1506
1538
|
const sum = acc + balance;
|
|
1507
|
-
return sum
|
|
1539
|
+
return sum >= exceptedBalance ? undefined : sum;
|
|
1508
1540
|
},
|
|
1509
1541
|
inputsBalance,
|
|
1510
1542
|
);
|
|
1543
|
+
|
|
1544
|
+
if (accumulated === undefined) {
|
|
1545
|
+
return addedCount;
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
throw new Error(
|
|
1549
|
+
`Insufficient coin, need ${exceptedBalance - accumulated} extra coin`,
|
|
1550
|
+
);
|
|
1511
1551
|
}
|
|
1512
1552
|
|
|
1513
1553
|
estimateFee(feeRate: NumLike): Num {
|
|
@@ -1524,17 +1564,31 @@ export class Transaction {
|
|
|
1524
1564
|
// Complete all inputs extra infos for cache
|
|
1525
1565
|
await this.getInputsCapacity(from.client);
|
|
1526
1566
|
|
|
1527
|
-
let leastFee =
|
|
1567
|
+
let leastFee = Zero;
|
|
1528
1568
|
let leastExtraCapacity = Zero;
|
|
1529
1569
|
|
|
1530
1570
|
while (true) {
|
|
1531
1571
|
const prepared = await from.prepareTransaction(this.clone());
|
|
1532
|
-
const collected = await
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1572
|
+
const collected = await (async () => {
|
|
1573
|
+
try {
|
|
1574
|
+
return await prepared.completeInputsByCapacity(
|
|
1575
|
+
from,
|
|
1576
|
+
leastFee + leastExtraCapacity,
|
|
1577
|
+
filter,
|
|
1578
|
+
);
|
|
1579
|
+
} catch (err) {
|
|
1580
|
+
if (leastExtraCapacity !== Zero) {
|
|
1581
|
+
throw new Error("Not enough capacity for the change cell");
|
|
1582
|
+
}
|
|
1537
1583
|
|
|
1584
|
+
throw err;
|
|
1585
|
+
}
|
|
1586
|
+
})();
|
|
1587
|
+
|
|
1588
|
+
if (leastFee === Zero) {
|
|
1589
|
+
// The initial fee is calculated based on prepared transaction
|
|
1590
|
+
leastFee = prepared.estimateFee(feeRate);
|
|
1591
|
+
}
|
|
1538
1592
|
const extraCapacity =
|
|
1539
1593
|
(await prepared.getInputsCapacity(from.client)) -
|
|
1540
1594
|
prepared.getOutputsCapacity();
|
package/src/client/client.ts
CHANGED
|
@@ -187,6 +187,38 @@ export const MAINNET_SCRIPTS: Record<
|
|
|
187
187
|
},
|
|
188
188
|
],
|
|
189
189
|
},
|
|
190
|
-
[KnownScript.SingleUseLock]:
|
|
191
|
-
|
|
190
|
+
[KnownScript.SingleUseLock]: {
|
|
191
|
+
codeHash:
|
|
192
|
+
"0x8290467a512e5b9a6b816469b0edabba1f4ac474e28ffdd604c2a7c76446bbaf",
|
|
193
|
+
hashType: "data1",
|
|
194
|
+
cellDeps: [
|
|
195
|
+
{
|
|
196
|
+
cellDep: {
|
|
197
|
+
outPoint: {
|
|
198
|
+
txHash:
|
|
199
|
+
"0x10d63a996157d32c01078058000052674ca58d15f921bec7f1dcdac2160eb66b",
|
|
200
|
+
index: 4,
|
|
201
|
+
},
|
|
202
|
+
depType: "code",
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
[KnownScript.OutputTypeProxyLock]: {
|
|
208
|
+
codeHash:
|
|
209
|
+
"0x2df53b592db3ae3685b7787adcfef0332a611edb83ca3feca435809964c3aff2",
|
|
210
|
+
hashType: "data1",
|
|
211
|
+
cellDeps: [
|
|
212
|
+
{
|
|
213
|
+
cellDep: {
|
|
214
|
+
outPoint: {
|
|
215
|
+
txHash:
|
|
216
|
+
"0x10d63a996157d32c01078058000052674ca58d15f921bec7f1dcdac2160eb66b",
|
|
217
|
+
index: 2,
|
|
218
|
+
},
|
|
219
|
+
depType: "code",
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
},
|
|
192
224
|
};
|
|
@@ -207,7 +207,7 @@ export const TESTNET_SCRIPTS: Record<
|
|
|
207
207
|
cellDep: {
|
|
208
208
|
outPoint: {
|
|
209
209
|
txHash:
|
|
210
|
-
"
|
|
210
|
+
"0xb4f171c9c9caf7401f54a8e56225ae21d95032150a87a4678eac3f66a3137b93",
|
|
211
211
|
index: 4,
|
|
212
212
|
},
|
|
213
213
|
depType: "code",
|
|
@@ -217,14 +217,14 @@ export const TESTNET_SCRIPTS: Record<
|
|
|
217
217
|
},
|
|
218
218
|
[KnownScript.OutputTypeProxyLock]: {
|
|
219
219
|
codeHash:
|
|
220
|
-
"
|
|
220
|
+
"0x2df53b592db3ae3685b7787adcfef0332a611edb83ca3feca435809964c3aff2",
|
|
221
221
|
hashType: "data1",
|
|
222
222
|
cellDeps: [
|
|
223
223
|
{
|
|
224
224
|
cellDep: {
|
|
225
225
|
outPoint: {
|
|
226
226
|
txHash:
|
|
227
|
-
"
|
|
227
|
+
"0xb4f171c9c9caf7401f54a8e56225ae21d95032150a87a4678eac3f66a3137b93",
|
|
228
228
|
index: 2,
|
|
229
229
|
},
|
|
230
230
|
depType: "code",
|
|
@@ -10,17 +10,17 @@ export function clientSearchKeyRangeFrom([a, b]: [NumLike, NumLike]): [
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export type ClientCollectableSearchKeyFilterLike = {
|
|
13
|
-
script?: ScriptLike;
|
|
14
|
-
scriptLenRange?: [NumLike, NumLike];
|
|
15
|
-
outputData?: HexLike;
|
|
16
|
-
outputDataSearchMode?: "prefix" | "exact" | "partial";
|
|
17
|
-
outputDataLenRange?: [NumLike, NumLike];
|
|
18
|
-
outputCapacityRange?: [NumLike, NumLike];
|
|
13
|
+
script?: ScriptLike | null;
|
|
14
|
+
scriptLenRange?: [NumLike, NumLike] | null;
|
|
15
|
+
outputData?: HexLike | null;
|
|
16
|
+
outputDataSearchMode?: "prefix" | "exact" | "partial" | null;
|
|
17
|
+
outputDataLenRange?: [NumLike, NumLike] | null;
|
|
18
|
+
outputCapacityRange?: [NumLike, NumLike] | null;
|
|
19
19
|
};
|
|
20
20
|
export type ClientCollectableSearchKeyLike = {
|
|
21
21
|
script: ScriptLike;
|
|
22
22
|
scriptType: "lock" | "type";
|
|
23
23
|
scriptSearchMode: "prefix" | "exact" | "partial";
|
|
24
|
-
filter?: ClientCollectableSearchKeyFilterLike;
|
|
25
|
-
withData?: boolean;
|
|
24
|
+
filter?: ClientCollectableSearchKeyFilterLike | null;
|
|
25
|
+
withData?: boolean | null;
|
|
26
26
|
};
|