@ckb-ccc/core 0.0.4-alpha.1 → 0.0.4-alpha.12
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/README.md +12 -7
- package/dist/address/address.advanced.d.ts +34 -0
- package/dist/address/address.advanced.d.ts.map +1 -1
- package/dist/address/address.advanced.js +41 -7
- package/dist/address/index.d.ts +36 -0
- package/dist/address/index.d.ts.map +1 -1
- package/dist/address/index.js +44 -5
- package/dist/bytes/advanced.d.ts +3 -0
- package/dist/bytes/advanced.d.ts.map +1 -1
- package/dist/bytes/index.d.ts +57 -0
- package/dist/bytes/index.d.ts.map +1 -1
- package/dist/bytes/index.js +57 -0
- package/dist/ckb/script.d.ts +98 -1
- package/dist/ckb/script.d.ts.map +1 -1
- package/dist/ckb/script.js +98 -1
- package/dist/ckb/transaction.d.ts +392 -1
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +403 -1
- package/dist/client/advanced.d.ts +1 -0
- package/dist/client/advanced.d.ts.map +1 -1
- package/dist/client/advanced.js +1 -0
- package/dist/client/client.d.ts +10 -8
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +18 -0
- package/dist/client/clientPublicMainnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.d.ts +3 -3
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.js +2 -2
- package/dist/client/clientPublicTestnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.d.ts +3 -3
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +2 -2
- package/dist/client/clientTypes.d.ts +6 -0
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/jsonRpc/advanced.d.ts +2 -87
- package/dist/client/jsonRpc/advanced.d.ts.map +1 -1
- package/dist/client/jsonRpc/advanced.js +2 -65
- package/dist/client/jsonRpc/index.d.ts +60 -6
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +72 -7
- package/dist/client/jsonRpc/transformers.d.ts +28 -0
- package/dist/client/jsonRpc/transformers.d.ts.map +1 -0
- package/dist/client/jsonRpc/transformers.js +122 -0
- package/dist/client/jsonRpc/types.d.ts +41 -0
- package/dist/client/jsonRpc/types.d.ts.map +1 -0
- package/dist/client/jsonRpc/types.js +1 -0
- package/dist/fixedPoint/index.d.ts +43 -1
- package/dist/fixedPoint/index.d.ts.map +1 -1
- package/dist/fixedPoint/index.js +39 -1
- package/dist/hasher/index.d.ts +43 -2
- package/dist/hasher/index.d.ts.map +1 -1
- package/dist/hasher/index.js +42 -0
- package/dist/hex/index.d.ts +19 -0
- package/dist/hex/index.d.ts.map +1 -1
- package/dist/hex/index.js +12 -0
- package/dist/num/index.d.ts +99 -0
- package/dist/num/index.d.ts.map +1 -1
- package/dist/num/index.js +92 -0
- package/dist/signer/btc/signerBtc.d.ts +40 -2
- package/dist/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist/signer/btc/signerBtc.js +36 -4
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +48 -0
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
- package/dist/signer/btc/signerBtcPublicKeyReadonly.js +52 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +47 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist/signer/ckb/signerCkbScriptReadonly.js +51 -0
- package/dist/signer/evm/signerEvm.d.ts +34 -2
- package/dist/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist/signer/evm/signerEvm.js +35 -4
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts +43 -1
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
- package/dist/signer/evm/signerEvmAddressReadonly.js +46 -0
- package/dist/signer/helpers.d.ts +35 -2
- package/dist/signer/helpers.d.ts.map +1 -1
- package/dist/signer/helpers.js +68 -11
- package/dist/signer/signer.d.ts +98 -7
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +70 -3
- package/package.json +3 -3
- package/src/address/address.advanced.ts +54 -18
- package/src/address/index.ts +51 -7
- package/src/bytes/advanced.ts +12 -9
- package/src/bytes/index.ts +60 -0
- package/src/ckb/script.ts +111 -2
- package/src/ckb/transaction.ts +455 -2
- package/src/client/advanced.ts +1 -0
- package/src/client/client.ts +31 -8
- package/src/client/clientPublicMainnet.advanced.ts +5 -2
- package/src/client/clientPublicMainnet.ts +6 -4
- package/src/client/clientPublicTestnet.advanced.ts +5 -2
- package/src/client/clientPublicTestnet.ts +6 -4
- package/src/client/clientTypes.ts +13 -0
- package/src/client/index.ts +1 -0
- package/src/client/jsonRpc/advanced.ts +2 -93
- package/src/client/jsonRpc/index.ts +99 -11
- package/src/client/jsonRpc/transformers.ts +161 -0
- package/src/client/jsonRpc/types.ts +48 -0
- package/src/fixedPoint/index.ts +52 -2
- package/src/hasher/index.ts +47 -1
- package/src/hex/index.ts +19 -0
- package/src/num/index.ts +101 -0
- package/src/signer/btc/signerBtc.ts +47 -4
- package/src/signer/btc/signerBtcPublicKeyReadonly.ts +54 -0
- package/src/signer/ckb/signerCkbScriptReadonly.ts +54 -0
- package/src/signer/evm/signerEvm.ts +42 -4
- package/src/signer/evm/signerEvmAddressReadonly.ts +50 -1
- package/src/signer/helpers.ts +89 -11
- package/src/signer/signer.ts +109 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAClE,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,MAAM,CAAC;AAElD,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,eAAe,CAAC;IAC3B,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,GAAG,CAAC;IACX,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,eAAe,EAAE,eAAe,CAAC;IACjC,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,GAAG,CAAC;IACd,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,eAAe,CAAC;IAC3B,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,GAAG,CAAC;IACb,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,WAAW,EAAE,GAAG,EAAE,CAAC;IACnB,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,YAAY,EAAE,GAAG,EAAE,CAAC;IACpB,SAAS,EAAE,GAAG,EAAE,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a fixed point value as a bigint.
|
|
3
|
+
*/
|
|
1
4
|
export type FixedPoint = bigint;
|
|
5
|
+
/**
|
|
6
|
+
* Represents a value that can be converted to a fixed point value.
|
|
7
|
+
* It can be a bigint, string, or number.
|
|
8
|
+
*/
|
|
2
9
|
export type FixedPointLike = bigint | string | number;
|
|
3
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Converts a FixedPointLike value to its string representation with fixed-point decimals.
|
|
12
|
+
*
|
|
13
|
+
* @param val - The value to convert, which can be a bigint, string, or number.
|
|
14
|
+
* @param decimals - The number of decimal places for the fixed-point representation. Default is 8.
|
|
15
|
+
* @returns A string representing the fixed-point value.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const str = fixedPointToString(123456789n, 8); // Outputs "1.23456789"
|
|
20
|
+
* const strFromString = fixedPointToString("123456789", 8); // Outputs "1.23456789"
|
|
21
|
+
* const strFromNumber = fixedPointToString(123456789, 8); // Outputs "1.23456789"
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function fixedPointToString(val: FixedPointLike, decimals?: number): string;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a FixedPointLike value to a FixedPoint (bigint) with fixed-point decimals.
|
|
27
|
+
*
|
|
28
|
+
* @param val - The value to convert, which can be a bigint, string, or number.
|
|
29
|
+
* @param decimals - The number of decimal places for the fixed-point representation. Default is 8.
|
|
30
|
+
* @returns A FixedPoint (bigint) representing the value with fixed-point decimals.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const fixedPoint = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
35
|
+
* const fixedPointFromString = fixedPointFrom("1.23456789", 8); // Outputs 123456789n
|
|
36
|
+
* const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
4
39
|
export declare function fixedPointFrom(val: FixedPointLike, decimals?: number): FixedPoint;
|
|
40
|
+
/**
|
|
41
|
+
* Represents the fixed point value of zero as a bigint.
|
|
42
|
+
*/
|
|
5
43
|
export declare const Zero = 0n;
|
|
44
|
+
/**
|
|
45
|
+
* Represents the fixed point value of one as a FixedPoint (bigint).
|
|
46
|
+
* Equivalent to 1 in fixed-point representation with default decimals (8).
|
|
47
|
+
*/
|
|
6
48
|
export declare const One: bigint;
|
|
7
49
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fixedPoint/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fixedPoint/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;GAGG;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEtD;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,SAAI,GAAG,MAAM,CAS5E;AAED;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,SAAI,GAAG,UAAU,CAY5E;AAED;;GAEG;AAEH,eAAO,MAAM,IAAI,KAAK,CAAC;AAEvB;;;GAGG;AAEH,eAAO,MAAM,GAAG,QAAsB,CAAC"}
|
package/dist/fixedPoint/index.js
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a fixed point value as a bigint.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Converts a FixedPointLike value to its string representation with fixed-point decimals.
|
|
6
|
+
*
|
|
7
|
+
* @param val - The value to convert, which can be a bigint, string, or number.
|
|
8
|
+
* @param decimals - The number of decimal places for the fixed-point representation. Default is 8.
|
|
9
|
+
* @returns A string representing the fixed-point value.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const str = fixedPointToString(123456789n, 8); // Outputs "1.23456789"
|
|
14
|
+
* const strFromString = fixedPointToString("123456789", 8); // Outputs "1.23456789"
|
|
15
|
+
* const strFromNumber = fixedPointToString(123456789, 8); // Outputs "1.23456789"
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
1
18
|
export function fixedPointToString(val, decimals = 8) {
|
|
2
|
-
const str = val.toString();
|
|
19
|
+
const str = fixedPointFrom(val).toString();
|
|
3
20
|
const l = str.length <= decimals ? "0" : str.slice(0, -decimals);
|
|
4
21
|
const r = str.slice(-decimals).padStart(decimals, "0").replace(/0*$/, "");
|
|
5
22
|
if (r === "") {
|
|
@@ -7,6 +24,20 @@ export function fixedPointToString(val, decimals = 8) {
|
|
|
7
24
|
}
|
|
8
25
|
return `${l}.${r}`;
|
|
9
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Converts a FixedPointLike value to a FixedPoint (bigint) with fixed-point decimals.
|
|
29
|
+
*
|
|
30
|
+
* @param val - The value to convert, which can be a bigint, string, or number.
|
|
31
|
+
* @param decimals - The number of decimal places for the fixed-point representation. Default is 8.
|
|
32
|
+
* @returns A FixedPoint (bigint) representing the value with fixed-point decimals.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const fixedPoint = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
37
|
+
* const fixedPointFromString = fixedPointFrom("1.23456789", 8); // Outputs 123456789n
|
|
38
|
+
* const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
10
41
|
export function fixedPointFrom(val, decimals = 8) {
|
|
11
42
|
if (typeof val === "bigint") {
|
|
12
43
|
return val;
|
|
@@ -18,5 +49,12 @@ export function fixedPointFrom(val, decimals = 8) {
|
|
|
18
49
|
}
|
|
19
50
|
return lVal + BigInt(r.slice(0, decimals).padEnd(decimals, "0"));
|
|
20
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Represents the fixed point value of zero as a bigint.
|
|
54
|
+
*/
|
|
21
55
|
export const Zero = 0n;
|
|
56
|
+
/**
|
|
57
|
+
* Represents the fixed point value of one as a FixedPoint (bigint).
|
|
58
|
+
* Equivalent to 1 in fixed-point representation with default decimals (8).
|
|
59
|
+
*/
|
|
22
60
|
export const One = fixedPointFrom("1");
|
package/dist/hasher/index.d.ts
CHANGED
|
@@ -1,11 +1,52 @@
|
|
|
1
|
-
import { Blake2b } from "blake2b";
|
|
2
1
|
import { BytesLike } from "../bytes";
|
|
3
2
|
import { Hex } from "../hex";
|
|
4
3
|
export declare class Hasher {
|
|
5
|
-
hasher
|
|
4
|
+
private readonly hasher;
|
|
5
|
+
/**
|
|
6
|
+
* Creates an instance of Hasher.
|
|
7
|
+
*
|
|
8
|
+
* @param outLength - The output length of the hash in bytes. Default is 32.
|
|
9
|
+
* @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
|
|
10
|
+
*/
|
|
6
11
|
constructor(outLength?: number, personal?: string);
|
|
12
|
+
/**
|
|
13
|
+
* Updates the hash with the given data.
|
|
14
|
+
*
|
|
15
|
+
* @param data - The data to update the hash with.
|
|
16
|
+
* @returns The current Hasher instance for chaining.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const hasher = new Hasher();
|
|
21
|
+
* hasher.update("some data").update("more data");
|
|
22
|
+
* const hash = hasher.digest();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
7
25
|
update(data: BytesLike): Hasher;
|
|
26
|
+
/**
|
|
27
|
+
* Finalizes the hash and returns the digest as a hexadecimal string.
|
|
28
|
+
*
|
|
29
|
+
* @returns The hexadecimal string representation of the hash.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const hasher = new Hasher();
|
|
34
|
+
* hasher.update("some data");
|
|
35
|
+
* const hash = hasher.digest(); // Outputs something like "0x..."
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
8
38
|
digest(): Hex;
|
|
9
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Computes the CKB hash of the given data using the Blake2b algorithm.
|
|
42
|
+
*
|
|
43
|
+
* @param data - The data to hash.
|
|
44
|
+
* @returns The hexadecimal string representation of the hash.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const hash = ckbHash("some data"); // Outputs something like "0x..."
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
10
51
|
export declare function ckbHash(data: BytesLike): Hex;
|
|
11
52
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hasher/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hasher/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAa,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAG7B,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC;;;;;OAKG;gBAES,SAAS,SAAK,EAAE,QAAQ,SAAuB;IAS3D;;;;;;;;;;;;OAYG;IAEH,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM;IAK/B;;;;;;;;;;;OAWG;IAEH,MAAM,IAAI,GAAG;CAGd;AAED;;;;;;;;;;GAUG;AAEH,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,GAAG,CAE5C"}
|
package/dist/hasher/index.js
CHANGED
|
@@ -2,17 +2,59 @@ import blake2b from "blake2b";
|
|
|
2
2
|
import { bytesFrom } from "../bytes";
|
|
3
3
|
import { CKB_BLAKE2B_PERSONAL } from "./advanced";
|
|
4
4
|
export class Hasher {
|
|
5
|
+
/**
|
|
6
|
+
* Creates an instance of Hasher.
|
|
7
|
+
*
|
|
8
|
+
* @param outLength - The output length of the hash in bytes. Default is 32.
|
|
9
|
+
* @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
|
|
10
|
+
*/
|
|
5
11
|
constructor(outLength = 32, personal = CKB_BLAKE2B_PERSONAL) {
|
|
6
12
|
this.hasher = blake2b(outLength, undefined, undefined, bytesFrom(personal, "utf8"));
|
|
7
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Updates the hash with the given data.
|
|
16
|
+
*
|
|
17
|
+
* @param data - The data to update the hash with.
|
|
18
|
+
* @returns The current Hasher instance for chaining.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const hasher = new Hasher();
|
|
23
|
+
* hasher.update("some data").update("more data");
|
|
24
|
+
* const hash = hasher.digest();
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
8
27
|
update(data) {
|
|
9
28
|
this.hasher.update(bytesFrom(data));
|
|
10
29
|
return this;
|
|
11
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Finalizes the hash and returns the digest as a hexadecimal string.
|
|
33
|
+
*
|
|
34
|
+
* @returns The hexadecimal string representation of the hash.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const hasher = new Hasher();
|
|
39
|
+
* hasher.update("some data");
|
|
40
|
+
* const hash = hasher.digest(); // Outputs something like "0x..."
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
12
43
|
digest() {
|
|
13
44
|
return `0x${this.hasher.digest("hex")}`;
|
|
14
45
|
}
|
|
15
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Computes the CKB hash of the given data using the Blake2b algorithm.
|
|
49
|
+
*
|
|
50
|
+
* @param data - The data to hash.
|
|
51
|
+
* @returns The hexadecimal string representation of the hash.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const hash = ckbHash("some data"); // Outputs something like "0x..."
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
16
58
|
export function ckbHash(data) {
|
|
17
59
|
return new Hasher().update(data).digest();
|
|
18
60
|
}
|
package/dist/hex/index.d.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import { BytesLike } from "../bytes";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a hexadecimal string prefixed with "0x".
|
|
4
|
+
*/
|
|
2
5
|
export type Hex = `0x${string}`;
|
|
6
|
+
/**
|
|
7
|
+
* Represents a value that can be converted to a hexadecimal string.
|
|
8
|
+
* It extends the BytesLike type.
|
|
9
|
+
*/
|
|
3
10
|
export type HexLike = BytesLike;
|
|
11
|
+
/**
|
|
12
|
+
* Converts a HexLike value to a Hex string.
|
|
13
|
+
*
|
|
14
|
+
* @param hex - The value to convert, which can be a string, Uint8Array, ArrayBuffer, or number array.
|
|
15
|
+
* @returns A Hex string representing the value.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const hexString = hexFrom("68656c6c6f"); // Outputs "0x68656c6c6f"
|
|
20
|
+
* const hexStringFromBytes = hexFrom(new Uint8Array([104, 101, 108, 108, 111])); // Outputs "0x68656c6c6f"
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
4
23
|
export declare function hexFrom(hex: HexLike): Hex;
|
|
5
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/hex/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hex/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAW,MAAM,UAAU,CAAC;AAEzD,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAChC,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC;AAEhC,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAEzC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hex/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAW,MAAM,UAAU,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAChC;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC;AAEhC;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAEzC"}
|
package/dist/hex/index.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { bytesFrom, bytesTo } from "../bytes";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a HexLike value to a Hex string.
|
|
4
|
+
*
|
|
5
|
+
* @param hex - The value to convert, which can be a string, Uint8Array, ArrayBuffer, or number array.
|
|
6
|
+
* @returns A Hex string representing the value.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const hexString = hexFrom("68656c6c6f"); // Outputs "0x68656c6c6f"
|
|
11
|
+
* const hexStringFromBytes = hexFrom(new Uint8Array([104, 101, 108, 108, 111])); // Outputs "0x68656c6c6f"
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
2
14
|
export function hexFrom(hex) {
|
|
3
15
|
return `0x${bytesTo(bytesFrom(hex), "hex")}`;
|
|
4
16
|
}
|
package/dist/num/index.d.ts
CHANGED
|
@@ -1,13 +1,112 @@
|
|
|
1
1
|
import { Bytes, BytesLike } from "../bytes";
|
|
2
2
|
import { Hex, HexLike } from "../hex";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a numeric value as a bigint.
|
|
5
|
+
*/
|
|
3
6
|
export type Num = bigint;
|
|
7
|
+
/**
|
|
8
|
+
* Represents a value that can be converted to a numeric value.
|
|
9
|
+
* It can be a string, number, bigint, or HexLike.
|
|
10
|
+
*/
|
|
4
11
|
export type NumLike = string | number | bigint | HexLike;
|
|
12
|
+
/**
|
|
13
|
+
* Converts a NumLike value to a Num (bigint).
|
|
14
|
+
*
|
|
15
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
16
|
+
* @returns A Num (bigint) representing the value.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const num = numFrom("12345"); // Outputs 12345n
|
|
21
|
+
* const numFromHex = numFrom("0x3039"); // Outputs 12345n
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
5
24
|
export declare function numFrom(val: NumLike): Num;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a NumLike value to a hexadecimal string.
|
|
27
|
+
*
|
|
28
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
29
|
+
* @returns A Hex string representing the numeric value.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const hex = numToHex(12345); // Outputs "0x3039"
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
6
36
|
export declare function numToHex(val: NumLike): Hex;
|
|
37
|
+
/**
|
|
38
|
+
* Converts a NumLike value to a byte array in little-endian order.
|
|
39
|
+
*
|
|
40
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
41
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
42
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const bytes = numToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
7
49
|
export declare function numToBytes(val: NumLike, bytes?: number): Bytes;
|
|
50
|
+
/**
|
|
51
|
+
* Converts a NumLike value to a byte array in little-endian order.
|
|
52
|
+
*
|
|
53
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
54
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
55
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const bytes = numLeToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
8
62
|
export declare function numLeToBytes(val: NumLike, bytes?: number): Bytes;
|
|
63
|
+
/**
|
|
64
|
+
* Converts a NumLike value to a byte array in big-endian order.
|
|
65
|
+
*
|
|
66
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
67
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
68
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const bytes = numBeToBytes(12345, 4); // Outputs Uint8Array [0, 0, 48, 57]
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
9
75
|
export declare function numBeToBytes(val: NumLike, bytes?: number): Bytes;
|
|
76
|
+
/**
|
|
77
|
+
* Converts a byte array to a Num (bigint) assuming little-endian order.
|
|
78
|
+
*
|
|
79
|
+
* @param val - The byte array to convert.
|
|
80
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const num = numFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
10
87
|
export declare function numFromBytes(val: BytesLike): Num;
|
|
88
|
+
/**
|
|
89
|
+
* Converts a byte array to a Num (bigint) assuming little-endian order.
|
|
90
|
+
*
|
|
91
|
+
* @param val - The byte array to convert.
|
|
92
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const num = numLeFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
11
99
|
export declare function numLeFromBytes(val: BytesLike): Num;
|
|
100
|
+
/**
|
|
101
|
+
* Converts a byte array to a Num (bigint) assuming big-endian order.
|
|
102
|
+
*
|
|
103
|
+
* @param val - The byte array to convert.
|
|
104
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const num = numBeFromBytes(new Uint8Array([0, 0, 48, 57])); // Outputs 12345n
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
12
111
|
export declare function numBeFromBytes(val: BytesLike): Num;
|
|
13
112
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/num/index.d.ts.map
CHANGED
|
@@ -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,UAAU,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/num/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,QAAQ,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AAEzB;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAUzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAE1C;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAE9D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAEhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAUhE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAEhD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAElD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAElD"}
|
package/dist/num/index.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { bytesConcat, bytesFrom } from "../bytes";
|
|
2
2
|
import { hexFrom } from "../hex";
|
|
3
|
+
/**
|
|
4
|
+
* Converts a NumLike value to a Num (bigint).
|
|
5
|
+
*
|
|
6
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
7
|
+
* @returns A Num (bigint) representing the value.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const num = numFrom("12345"); // Outputs 12345n
|
|
12
|
+
* const numFromHex = numFrom("0x3039"); // Outputs 12345n
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
3
15
|
export function numFrom(val) {
|
|
4
16
|
if (typeof val === "bigint") {
|
|
5
17
|
return val;
|
|
@@ -9,15 +21,62 @@ export function numFrom(val) {
|
|
|
9
21
|
}
|
|
10
22
|
return BigInt(hexFrom(val));
|
|
11
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts a NumLike value to a hexadecimal string.
|
|
26
|
+
*
|
|
27
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
28
|
+
* @returns A Hex string representing the numeric value.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const hex = numToHex(12345); // Outputs "0x3039"
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
12
35
|
export function numToHex(val) {
|
|
13
36
|
return `0x${numFrom(val).toString(16)}`;
|
|
14
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts a NumLike value to a byte array in little-endian order.
|
|
40
|
+
*
|
|
41
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
42
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
43
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const bytes = numToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
15
50
|
export function numToBytes(val, bytes) {
|
|
16
51
|
return numLeToBytes(val, bytes);
|
|
17
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Converts a NumLike value to a byte array in little-endian order.
|
|
55
|
+
*
|
|
56
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
57
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
58
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const bytes = numLeToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
18
65
|
export function numLeToBytes(val, bytes) {
|
|
19
66
|
return numBeToBytes(val, bytes).reverse();
|
|
20
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Converts a NumLike value to a byte array in big-endian order.
|
|
70
|
+
*
|
|
71
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
72
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
73
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const bytes = numBeToBytes(12345, 4); // Outputs Uint8Array [0, 0, 48, 57]
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
21
80
|
export function numBeToBytes(val, bytes) {
|
|
22
81
|
const rawBytes = bytesFrom(numFrom(val).toString(16));
|
|
23
82
|
if (bytes == null) {
|
|
@@ -25,12 +84,45 @@ export function numBeToBytes(val, bytes) {
|
|
|
25
84
|
}
|
|
26
85
|
return bytesConcat(Array.from(Array(bytes - rawBytes.length), () => 0), rawBytes);
|
|
27
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Converts a byte array to a Num (bigint) assuming little-endian order.
|
|
89
|
+
*
|
|
90
|
+
* @param val - The byte array to convert.
|
|
91
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const num = numFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
28
98
|
export function numFromBytes(val) {
|
|
29
99
|
return numLeFromBytes(val);
|
|
30
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Converts a byte array to a Num (bigint) assuming little-endian order.
|
|
103
|
+
*
|
|
104
|
+
* @param val - The byte array to convert.
|
|
105
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const num = numLeFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
31
112
|
export function numLeFromBytes(val) {
|
|
32
113
|
return numBeFromBytes(bytesFrom(val).reverse());
|
|
33
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Converts a byte array to a Num (bigint) assuming big-endian order.
|
|
117
|
+
*
|
|
118
|
+
* @param val - The byte array to convert.
|
|
119
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const num = numBeFromBytes(new Uint8Array([0, 0, 48, 57])); // Outputs 12345n
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
34
126
|
export function numBeFromBytes(val) {
|
|
35
127
|
return numFrom(bytesFrom(val));
|
|
36
128
|
}
|
|
@@ -1,12 +1,50 @@
|
|
|
1
1
|
import { Address } from "../../address";
|
|
2
|
-
import { Transaction } from "../../ckb";
|
|
2
|
+
import { Transaction, TransactionLike } from "../../ckb";
|
|
3
3
|
import { HexLike } from "../../hex";
|
|
4
4
|
import { Signer } from "../signer";
|
|
5
|
+
/**
|
|
6
|
+
* An abstract class extending the Signer class for Bitcoin-like signing operations.
|
|
7
|
+
* This class provides methods to get Bitcoin account, public key, and internal address,
|
|
8
|
+
* as well as signing transactions.
|
|
9
|
+
*/
|
|
5
10
|
export declare abstract class SignerBtc extends Signer {
|
|
11
|
+
/**
|
|
12
|
+
* Gets the Bitcoin account associated with the signer.
|
|
13
|
+
*
|
|
14
|
+
* @returns A promise that resolves to a string representing the Bitcoin account.
|
|
15
|
+
*/
|
|
6
16
|
abstract getBtcAccount(): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the Bitcoin public key associated with the signer.
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise that resolves to a HexLike value representing the Bitcoin public key.
|
|
21
|
+
*/
|
|
7
22
|
abstract getBtcPublicKey(): Promise<HexLike>;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the internal address, which is the Bitcoin account in this case.
|
|
25
|
+
*
|
|
26
|
+
* @returns A promise that resolves to a string representing the internal address.
|
|
27
|
+
*/
|
|
8
28
|
getInternalAddress(): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Gets an array of Address objects representing the known script addresses for the signer.
|
|
31
|
+
*
|
|
32
|
+
* @returns A promise that resolves to an array of Address objects.
|
|
33
|
+
*/
|
|
9
34
|
getAddressObjs(): Promise<Address[]>;
|
|
10
|
-
|
|
35
|
+
/**
|
|
36
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
37
|
+
*
|
|
38
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
39
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
40
|
+
*/
|
|
41
|
+
prepareTransaction(txLike: TransactionLike): Promise<Transaction>;
|
|
42
|
+
/**
|
|
43
|
+
* Signs a transaction without modifying it.
|
|
44
|
+
*
|
|
45
|
+
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
46
|
+
* @returns A promise that resolves to a signed Transaction object.
|
|
47
|
+
*/
|
|
48
|
+
signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
|
|
11
49
|
}
|
|
12
50
|
//# sourceMappingURL=signerBtc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signerBtc.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAe,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"signerBtc.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;;GAIG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAE5C;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAa1C;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAKvE;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAgCzE"}
|
|
@@ -2,16 +2,31 @@ import { ripemd160 } from "@noble/hashes/ripemd160";
|
|
|
2
2
|
import { sha256 } from "@noble/hashes/sha256";
|
|
3
3
|
import { Address } from "../../address";
|
|
4
4
|
import { bytesConcat, bytesFrom } from "../../bytes";
|
|
5
|
-
import { WitnessArgs } from "../../ckb";
|
|
5
|
+
import { Transaction, WitnessArgs } from "../../ckb";
|
|
6
6
|
import { KnownScript } from "../../client";
|
|
7
7
|
import { hexFrom } from "../../hex";
|
|
8
8
|
import { numToBytes } from "../../num";
|
|
9
|
-
import { getSignHashInfo } from "../helpers";
|
|
9
|
+
import { getSignHashInfo, prepareSighashAllWitness } from "../helpers";
|
|
10
10
|
import { Signer } from "../signer";
|
|
11
|
+
/**
|
|
12
|
+
* An abstract class extending the Signer class for Bitcoin-like signing operations.
|
|
13
|
+
* This class provides methods to get Bitcoin account, public key, and internal address,
|
|
14
|
+
* as well as signing transactions.
|
|
15
|
+
*/
|
|
11
16
|
export class SignerBtc extends Signer {
|
|
17
|
+
/**
|
|
18
|
+
* Gets the internal address, which is the Bitcoin account in this case.
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise that resolves to a string representing the internal address.
|
|
21
|
+
*/
|
|
12
22
|
async getInternalAddress() {
|
|
13
23
|
return this.getBtcAccount();
|
|
14
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Gets an array of Address objects representing the known script addresses for the signer.
|
|
27
|
+
*
|
|
28
|
+
* @returns A promise that resolves to an array of Address objects.
|
|
29
|
+
*/
|
|
15
30
|
async getAddressObjs() {
|
|
16
31
|
const publicKey = await this.getBtcPublicKey();
|
|
17
32
|
const hash = ripemd160(sha256(bytesFrom(publicKey)));
|
|
@@ -19,9 +34,26 @@ export class SignerBtc extends Signer {
|
|
|
19
34
|
await Address.fromKnownScript(KnownScript.OmniLock, hexFrom([0x04, ...hash, 0x00]), this.client),
|
|
20
35
|
];
|
|
21
36
|
}
|
|
22
|
-
|
|
37
|
+
/**
|
|
38
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
39
|
+
*
|
|
40
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
41
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
42
|
+
*/
|
|
43
|
+
async prepareTransaction(txLike) {
|
|
23
44
|
const { script } = await this.getRecommendedAddressObj();
|
|
24
|
-
|
|
45
|
+
return prepareSighashAllWitness(txLike, script, 85, this.client);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Signs a transaction without modifying it.
|
|
49
|
+
*
|
|
50
|
+
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
51
|
+
* @returns A promise that resolves to a signed Transaction object.
|
|
52
|
+
*/
|
|
53
|
+
async signOnlyTransaction(txLike) {
|
|
54
|
+
const tx = Transaction.from(txLike);
|
|
55
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
56
|
+
const info = await getSignHashInfo(tx, script, this.client);
|
|
25
57
|
if (!info) {
|
|
26
58
|
return tx;
|
|
27
59
|
}
|