@ckb-ccc/core 0.0.11-alpha.2 → 0.0.12-alpha.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/dist/address/index.d.ts.map +1 -1
- package/dist/ckb/script.d.ts +1 -5
- package/dist/ckb/script.d.ts.map +1 -1
- package/dist/ckb/transaction.d.ts +32 -39
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +58 -16
- package/dist/client/client.advanced.d.ts.map +1 -1
- package/dist/client/client.d.ts +1 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +10 -4
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +22 -2
- package/dist/client/clientPublicMainnet.d.ts +4 -1
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.js +3 -2
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.js +22 -2
- package/dist/client/clientPublicTestnet.d.ts +4 -1
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +3 -2
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/fixedPoint/index.d.ts +2 -2
- package/dist/fixedPoint/index.d.ts.map +1 -1
- package/dist/hasher/hasher.d.ts +32 -0
- package/dist/hasher/hasher.d.ts.map +1 -0
- package/dist/hasher/hasher.js +1 -0
- package/dist/hasher/hasherCkb.d.ts +68 -0
- package/dist/hasher/hasherCkb.d.ts.map +1 -0
- package/dist/hasher/hasherCkb.js +83 -0
- package/dist/hasher/hasherKeecak256.d.ts +38 -0
- package/dist/hasher/hasherKeecak256.d.ts.map +1 -0
- package/dist/hasher/hasherKeecak256.js +43 -0
- package/dist/hasher/index.d.ts +3 -66
- package/dist/hasher/index.d.ts.map +1 -1
- package/dist/hasher/index.js +3 -79
- package/dist/keystore/index.d.ts +2 -2
- package/dist/keystore/index.d.ts.map +1 -1
- package/dist/signer/evm/signerEvm.d.ts +13 -4
- package/dist/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist/signer/evm/signerEvm.js +63 -11
- package/dist/signer/signer/index.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist.commonjs/address/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/script.d.ts +1 -5
- package/dist.commonjs/ckb/script.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.d.ts +32 -39
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +57 -15
- package/dist.commonjs/client/client.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/client.d.ts +1 -0
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +10 -4
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +22 -2
- package/dist.commonjs/client/clientPublicMainnet.d.ts +4 -1
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.js +3 -2
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +22 -2
- package/dist.commonjs/client/clientPublicTestnet.d.ts +4 -1
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.js +3 -2
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/fixedPoint/index.d.ts +2 -2
- package/dist.commonjs/fixedPoint/index.d.ts.map +1 -1
- package/dist.commonjs/hasher/hasher.d.ts +32 -0
- package/dist.commonjs/hasher/hasher.d.ts.map +1 -0
- package/dist.commonjs/hasher/hasher.js +2 -0
- package/dist.commonjs/hasher/hasherCkb.d.ts +68 -0
- package/dist.commonjs/hasher/hasherCkb.d.ts.map +1 -0
- package/dist.commonjs/hasher/hasherCkb.js +89 -0
- package/dist.commonjs/hasher/hasherKeecak256.d.ts +38 -0
- package/dist.commonjs/hasher/hasherKeecak256.d.ts.map +1 -0
- package/dist.commonjs/hasher/hasherKeecak256.js +47 -0
- package/dist.commonjs/hasher/index.d.ts +3 -66
- package/dist.commonjs/hasher/index.d.ts.map +1 -1
- package/dist.commonjs/hasher/index.js +16 -85
- package/dist.commonjs/keystore/index.d.ts +2 -2
- package/dist.commonjs/keystore/index.d.ts.map +1 -1
- package/dist.commonjs/signer/evm/signerEvm.d.ts +13 -4
- package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist.commonjs/signer/evm/signerEvm.js +72 -20
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
- package/dist.commonjs/utils/index.d.ts +1 -1
- package/dist.commonjs/utils/index.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/address/index.ts +1 -1
- package/src/ckb/script.ts +1 -1
- package/src/ckb/transaction.ts +75 -22
- package/src/client/client.advanced.ts +1 -1
- package/src/client/client.ts +15 -4
- package/src/client/clientPublicMainnet.advanced.ts +25 -2
- package/src/client/clientPublicMainnet.ts +6 -2
- package/src/client/clientPublicTestnet.advanced.ts +25 -2
- package/src/client/clientPublicTestnet.ts +6 -2
- package/src/client/jsonRpc/index.ts +3 -3
- package/src/fixedPoint/index.ts +2 -2
- package/src/hasher/hasher.ts +35 -0
- package/src/hasher/hasherCkb.ts +102 -0
- package/src/hasher/hasherKeecak256.ts +52 -0
- package/src/hasher/index.ts +3 -103
- package/src/keystore/index.ts +19 -1
- package/src/signer/evm/signerEvm.ts +131 -24
- package/src/signer/signer/index.ts +1 -1
- package/src/utils/index.ts +2 -2
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BytesLike } from "../bytes/index.js";
|
|
2
|
+
import { Hex } from "../hex/index.js";
|
|
3
|
+
export interface Hasher {
|
|
4
|
+
/**
|
|
5
|
+
* Updates the hash with the given data.
|
|
6
|
+
*
|
|
7
|
+
* @param data - The data to update the hash with.
|
|
8
|
+
* @returns The current Hasher instance for chaining.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const hasher = new Hasher();
|
|
13
|
+
* hasher.update("some data").update("more data");
|
|
14
|
+
* const hash = hasher.digest();
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
update(data: BytesLike): Hasher;
|
|
18
|
+
/**
|
|
19
|
+
* Finalizes the hash and returns the digest as a hexadecimal string.
|
|
20
|
+
*
|
|
21
|
+
* @returns The hexadecimal string representation of the hash.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const hasher = new Hasher();
|
|
26
|
+
* hasher.update("some data");
|
|
27
|
+
* const hash = hasher.digest(); // Outputs something like "0x..."
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
digest(): Hex;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=hasher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasher.d.ts","sourceRoot":"","sources":["../../src/hasher/hasher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAEtC,MAAM,WAAW,MAAM;IACrB;;;;;;;;;;;;OAYG;IAEH,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC;IAEhC;;;;;;;;;;;OAWG;IAEH,MAAM,IAAI,GAAG,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { BytesLike } from "../bytes/index.js";
|
|
2
|
+
import { CellInputLike } from "../ckb/index.js";
|
|
3
|
+
import { Hex } from "../hex/index.js";
|
|
4
|
+
import { NumLike } from "../num/index.js";
|
|
5
|
+
import { Hasher } from "./hasher.js";
|
|
6
|
+
export declare class HasherCkb implements Hasher {
|
|
7
|
+
private readonly hasher;
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of Hasher.
|
|
10
|
+
*
|
|
11
|
+
* @param outLength - The output length of the hash in bytes. Default is 32.
|
|
12
|
+
* @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
|
|
13
|
+
*/
|
|
14
|
+
constructor(outLength?: number, personal?: string);
|
|
15
|
+
/**
|
|
16
|
+
* Updates the hash with the given data.
|
|
17
|
+
*
|
|
18
|
+
* @param data - The data to update the hash with.
|
|
19
|
+
* @returns The current Hasher instance for chaining.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const hasher = new Hasher();
|
|
24
|
+
* hasher.update("some data").update("more data");
|
|
25
|
+
* const hash = hasher.digest();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
update(data: BytesLike): HasherCkb;
|
|
29
|
+
/**
|
|
30
|
+
* Finalizes the hash and returns the digest as a hexadecimal string.
|
|
31
|
+
*
|
|
32
|
+
* @returns The hexadecimal string representation of the hash.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const hasher = new Hasher();
|
|
37
|
+
* hasher.update("some data");
|
|
38
|
+
* const hash = hasher.digest(); // Outputs something like "0x..."
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
digest(): Hex;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Computes the CKB hash of the given data using the Blake2b algorithm.
|
|
45
|
+
*
|
|
46
|
+
* @param data - The data to hash.
|
|
47
|
+
* @returns The hexadecimal string representation of the hash.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const hash = hashCkb("some data"); // Outputs something like "0x..."
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function hashCkb(...data: BytesLike[]): Hex;
|
|
55
|
+
/**
|
|
56
|
+
* Computes the Type ID hash of the given data.
|
|
57
|
+
*
|
|
58
|
+
* @param cellInput - The first cell input of the transaction.
|
|
59
|
+
* @param outputIndex - The output index of the Type ID cell.
|
|
60
|
+
* @returns The hexadecimal string representation of the hash.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const hash = hashTypeId(cellInput, outputIndex); // Outputs something like "0x..."
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function hashTypeId(cellInputLike: CellInputLike, outputIndex: NumLike): Hex;
|
|
68
|
+
//# sourceMappingURL=hasherCkb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasherCkb.d.ts","sourceRoot":"","sources":["../../src/hasher/hasherCkb.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAa,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAa,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAW,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAgB,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,qBAAa,SAAU,YAAW,MAAM;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyC;IAEhE;;;;;OAKG;gBAES,SAAS,SAAK,EAAE,QAAQ,SAAuB;IAO3D;;;;;;;;;;;;OAYG;IAEH,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS;IAKlC;;;;;;;;;;;OAWG;IAEH,MAAM,IAAI,GAAG;CAGd;AAED;;;;;;;;;;GAUG;AAEH,wBAAgB,OAAO,CAAC,GAAG,IAAI,EAAE,SAAS,EAAE,GAAG,GAAG,CAIjD;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,UAAU,CACxB,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,OAAO,GACnB,GAAG,CAKL"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { blake2b } from "@noble/hashes/blake2b";
|
|
2
|
+
import { bytesFrom } from "../bytes/index.js";
|
|
3
|
+
import { CellInput } from "../ckb/index.js";
|
|
4
|
+
import { hexFrom } from "../hex/index.js";
|
|
5
|
+
import { numLeToBytes } from "../num/index.js";
|
|
6
|
+
import { CKB_BLAKE2B_PERSONAL } from "./advanced.js";
|
|
7
|
+
export class HasherCkb {
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of Hasher.
|
|
10
|
+
*
|
|
11
|
+
* @param outLength - The output length of the hash in bytes. Default is 32.
|
|
12
|
+
* @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
|
|
13
|
+
*/
|
|
14
|
+
constructor(outLength = 32, personal = CKB_BLAKE2B_PERSONAL) {
|
|
15
|
+
this.hasher = blake2b.create({
|
|
16
|
+
personalization: personal,
|
|
17
|
+
dkLen: outLength,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Updates the hash with the given data.
|
|
22
|
+
*
|
|
23
|
+
* @param data - The data to update the hash with.
|
|
24
|
+
* @returns The current Hasher instance for chaining.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const hasher = new Hasher();
|
|
29
|
+
* hasher.update("some data").update("more data");
|
|
30
|
+
* const hash = hasher.digest();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
update(data) {
|
|
34
|
+
this.hasher.update(bytesFrom(data));
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Finalizes the hash and returns the digest as a hexadecimal string.
|
|
39
|
+
*
|
|
40
|
+
* @returns The hexadecimal string representation of the hash.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const hasher = new Hasher();
|
|
45
|
+
* hasher.update("some data");
|
|
46
|
+
* const hash = hasher.digest(); // Outputs something like "0x..."
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
digest() {
|
|
50
|
+
return hexFrom(this.hasher.digest());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Computes the CKB hash of the given data using the Blake2b algorithm.
|
|
55
|
+
*
|
|
56
|
+
* @param data - The data to hash.
|
|
57
|
+
* @returns The hexadecimal string representation of the hash.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const hash = hashCkb("some data"); // Outputs something like "0x..."
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export function hashCkb(...data) {
|
|
65
|
+
const hasher = new HasherCkb();
|
|
66
|
+
data.forEach((d) => hasher.update(d));
|
|
67
|
+
return hasher.digest();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Computes the Type ID hash of the given data.
|
|
71
|
+
*
|
|
72
|
+
* @param cellInput - The first cell input of the transaction.
|
|
73
|
+
* @param outputIndex - The output index of the Type ID cell.
|
|
74
|
+
* @returns The hexadecimal string representation of the hash.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const hash = hashTypeId(cellInput, outputIndex); // Outputs something like "0x..."
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function hashTypeId(cellInputLike, outputIndex) {
|
|
82
|
+
return hashCkb(CellInput.from(cellInputLike).toBytes(), numLeToBytes(outputIndex, 8));
|
|
83
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BytesLike } from "../bytes/index.js";
|
|
2
|
+
import { Hex } from "../hex/index.js";
|
|
3
|
+
import { Hasher } from "./hasher.js";
|
|
4
|
+
export declare class HasherKeecak256 implements Hasher {
|
|
5
|
+
private readonly hasher;
|
|
6
|
+
/**
|
|
7
|
+
* Creates an instance of Hasher.
|
|
8
|
+
*/
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Updates the hash with the given data.
|
|
12
|
+
*
|
|
13
|
+
* @param data - The data to update the hash with.
|
|
14
|
+
* @returns The current Hasher instance for chaining.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const hasher = new Hasher();
|
|
19
|
+
* hasher.update("some data").update("more data");
|
|
20
|
+
* const hash = hasher.digest();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
update(data: BytesLike): HasherKeecak256;
|
|
24
|
+
/**
|
|
25
|
+
* Finalizes the hash and returns the digest as a hexadecimal string.
|
|
26
|
+
*
|
|
27
|
+
* @returns The hexadecimal string representation of the hash.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const hasher = new Hasher();
|
|
32
|
+
* hasher.update("some data");
|
|
33
|
+
* const hash = hasher.digest(); // Outputs something like "0x..."
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
digest(): Hex;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=hasherKeecak256.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasherKeecak256.d.ts","sourceRoot":"","sources":["../../src/hasher/hasherKeecak256.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAa,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAW,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,qBAAa,eAAgB,YAAW,MAAM;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4C;IAEnE;;OAEG;;IAMH;;;;;;;;;;;;OAYG;IAEH,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,eAAe;IAKxC;;;;;;;;;;;OAWG;IAEH,MAAM,IAAI,GAAG;CAGd"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
|
2
|
+
import { bytesFrom } from "../bytes/index.js";
|
|
3
|
+
import { hexFrom } from "../hex/index.js";
|
|
4
|
+
export class HasherKeecak256 {
|
|
5
|
+
/**
|
|
6
|
+
* Creates an instance of Hasher.
|
|
7
|
+
*/
|
|
8
|
+
constructor() {
|
|
9
|
+
this.hasher = keccak_256.create();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Updates the hash with the given data.
|
|
13
|
+
*
|
|
14
|
+
* @param data - The data to update the hash with.
|
|
15
|
+
* @returns The current Hasher instance for chaining.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const hasher = new Hasher();
|
|
20
|
+
* hasher.update("some data").update("more data");
|
|
21
|
+
* const hash = hasher.digest();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
update(data) {
|
|
25
|
+
this.hasher.update(bytesFrom(data));
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Finalizes the hash and returns the digest as a hexadecimal string.
|
|
30
|
+
*
|
|
31
|
+
* @returns The hexadecimal string representation of the hash.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const hasher = new Hasher();
|
|
36
|
+
* hasher.update("some data");
|
|
37
|
+
* const hash = hasher.digest(); // Outputs something like "0x..."
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
digest() {
|
|
41
|
+
return hexFrom(this.hasher.digest());
|
|
42
|
+
}
|
|
43
|
+
}
|
package/dist/hasher/index.d.ts
CHANGED
|
@@ -1,67 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { NumLike } from "../num/index.js";
|
|
5
|
-
export declare class Hasher {
|
|
6
|
-
private readonly hasher;
|
|
7
|
-
/**
|
|
8
|
-
* Creates an instance of Hasher.
|
|
9
|
-
*
|
|
10
|
-
* @param outLength - The output length of the hash in bytes. Default is 32.
|
|
11
|
-
* @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
|
|
12
|
-
*/
|
|
13
|
-
constructor(outLength?: number, personal?: string);
|
|
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
|
-
*/
|
|
27
|
-
update(data: BytesLike): Hasher;
|
|
28
|
-
/**
|
|
29
|
-
* Finalizes the hash and returns the digest as a hexadecimal string.
|
|
30
|
-
*
|
|
31
|
-
* @returns The hexadecimal string representation of the hash.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* const hasher = new Hasher();
|
|
36
|
-
* hasher.update("some data");
|
|
37
|
-
* const hash = hasher.digest(); // Outputs something like "0x..."
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
digest(): Hex;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Computes the CKB hash of the given data using the Blake2b algorithm.
|
|
44
|
-
*
|
|
45
|
-
* @param data - The data to hash.
|
|
46
|
-
* @returns The hexadecimal string representation of the hash.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* const hash = hashCkb("some data"); // Outputs something like "0x..."
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export declare function hashCkb(...data: BytesLike[]): Hex;
|
|
54
|
-
/**
|
|
55
|
-
* Computes the Type ID hash of the given data.
|
|
56
|
-
*
|
|
57
|
-
* @param cellInput - The first cell input of the transaction.
|
|
58
|
-
* @param outputIndex - The output index of the Type ID cell.
|
|
59
|
-
* @returns The hexadecimal string representation of the hash.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```typescript
|
|
63
|
-
* const hash = hashTypeId(cellInput, outputIndex); // Outputs something like "0x..."
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export declare function hashTypeId(cellInputLike: CellInputLike, outputIndex: NumLike): Hex;
|
|
1
|
+
export * from "./hasher.js";
|
|
2
|
+
export * from "./hasherCkb.js";
|
|
3
|
+
export * from "./hasherKeecak256.js";
|
|
67
4
|
//# 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":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
|
package/dist/hasher/index.js
CHANGED
|
@@ -1,79 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { numLeToBytes } from "../num/index.js";
|
|
5
|
-
import { CKB_BLAKE2B_PERSONAL } from "./advanced.js";
|
|
6
|
-
export class Hasher {
|
|
7
|
-
/**
|
|
8
|
-
* Creates an instance of Hasher.
|
|
9
|
-
*
|
|
10
|
-
* @param outLength - The output length of the hash in bytes. Default is 32.
|
|
11
|
-
* @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
|
|
12
|
-
*/
|
|
13
|
-
constructor(outLength = 32, personal = CKB_BLAKE2B_PERSONAL) {
|
|
14
|
-
this.hasher = blake2b(outLength, undefined, undefined, bytesFrom(personal, "utf8"));
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Updates the hash with the given data.
|
|
18
|
-
*
|
|
19
|
-
* @param data - The data to update the hash with.
|
|
20
|
-
* @returns The current Hasher instance for chaining.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* const hasher = new Hasher();
|
|
25
|
-
* hasher.update("some data").update("more data");
|
|
26
|
-
* const hash = hasher.digest();
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
update(data) {
|
|
30
|
-
this.hasher.update(bytesFrom(data));
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Finalizes the hash and returns the digest as a hexadecimal string.
|
|
35
|
-
*
|
|
36
|
-
* @returns The hexadecimal string representation of the hash.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const hasher = new Hasher();
|
|
41
|
-
* hasher.update("some data");
|
|
42
|
-
* const hash = hasher.digest(); // Outputs something like "0x..."
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
digest() {
|
|
46
|
-
return `0x${this.hasher.digest("hex")}`;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Computes the CKB hash of the given data using the Blake2b algorithm.
|
|
51
|
-
*
|
|
52
|
-
* @param data - The data to hash.
|
|
53
|
-
* @returns The hexadecimal string representation of the hash.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* const hash = hashCkb("some data"); // Outputs something like "0x..."
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export function hashCkb(...data) {
|
|
61
|
-
const hasher = new Hasher();
|
|
62
|
-
data.forEach((d) => hasher.update(d));
|
|
63
|
-
return hasher.digest();
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Computes the Type ID hash of the given data.
|
|
67
|
-
*
|
|
68
|
-
* @param cellInput - The first cell input of the transaction.
|
|
69
|
-
* @param outputIndex - The output index of the Type ID cell.
|
|
70
|
-
* @returns The hexadecimal string representation of the hash.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```typescript
|
|
74
|
-
* const hash = hashTypeId(cellInput, outputIndex); // Outputs something like "0x..."
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export function hashTypeId(cellInputLike, outputIndex) {
|
|
78
|
-
return hashCkb(CellInput.from(cellInputLike).toBytes(), numLeToBytes(outputIndex, 8));
|
|
79
|
-
}
|
|
1
|
+
export * from "./hasher.js";
|
|
2
|
+
export * from "./hasherCkb.js";
|
|
3
|
+
export * from "./hasherKeecak256.js";
|
package/dist/keystore/index.d.ts
CHANGED
|
@@ -9,11 +9,11 @@ export declare function keystoreEncrypt(privateKeyLike: BytesLike, chainCodeLike
|
|
|
9
9
|
cipher: string;
|
|
10
10
|
kdf: string;
|
|
11
11
|
kdfparams: {
|
|
12
|
-
dklen: number;
|
|
13
|
-
salt: string;
|
|
14
12
|
n: number;
|
|
15
13
|
r: number;
|
|
16
14
|
p: number;
|
|
15
|
+
dklen: number;
|
|
16
|
+
salt: string;
|
|
17
17
|
};
|
|
18
18
|
mac: string;
|
|
19
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/keystore/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,mBAAmB,CAAC;AAgB7E,wBAAsB,eAAe,CACnC,cAAc,EAAE,SAAS,EACzB,aAAa,EAAE,SAAS,EACxB,QAAQ,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/keystore/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,mBAAmB,CAAC;AAgB7E,wBAAsB,eAAe,CACnC,cAAc,EAAE,SAAS,EACzB,aAAa,EAAE,SAAS,EACxB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IACT,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE;QACN,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE;YACZ,EAAE,EAAE,MAAM,CAAC;SACZ,CAAC;QACF,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,EAAE;YACT,CAAC,EAAE,MAAM,CAAC;YACV,CAAC,EAAE,MAAM,CAAC;YACV,CAAC,EAAE,MAAM,CAAC;YACV,KAAK,EAAE,MAAM,CAAC;YACd,IAAI,EAAE,MAAM,CAAC;SACd,CAAC;QACF,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH,CAAC,CAqCD;AAED,wBAAsB,eAAe,CACnC,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IACT,UAAU,EAAE,KAAK,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC;CAClB,CAAC,CAoED"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Address } from "../../address/index.js";
|
|
2
|
-
import { BytesLike } from "../../bytes/index.js";
|
|
2
|
+
import { Bytes, BytesLike } from "../../bytes/index.js";
|
|
3
3
|
import { Script, Transaction, TransactionLike } from "../../ckb/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Hasher } from "../../hasher/index.js";
|
|
5
|
+
import { Hex, HexLike } from "../../hex/index.js";
|
|
5
6
|
import { Signer, SignerSignType, SignerType } from "../signer/index.js";
|
|
6
7
|
/**
|
|
7
8
|
* An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
|
|
@@ -28,8 +29,11 @@ export declare abstract class SignerEvm extends Signer {
|
|
|
28
29
|
* @returns A promise that resolves to an array of Address objects.
|
|
29
30
|
*/
|
|
30
31
|
getAddressObjs(): Promise<Address[]>;
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
_getOmniLockAddresses(account: HexLike): Promise<Address[]>;
|
|
33
|
+
_getPWLockAddresses(account: HexLike): Promise<Address[]>;
|
|
34
|
+
_getOmniLockEvmAddressObj(account: HexLike): Promise<Address>;
|
|
35
|
+
_getOmniLockOldEvmAddressObj(account: HexLike): Promise<Address>;
|
|
36
|
+
_getPWLockEvmAddressObj(account: HexLike): Promise<Address | undefined>;
|
|
33
37
|
/**
|
|
34
38
|
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
35
39
|
*
|
|
@@ -45,5 +49,10 @@ export declare abstract class SignerEvm extends Signer {
|
|
|
45
49
|
*/
|
|
46
50
|
signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
|
|
47
51
|
_signOmniLockScriptForTransaction(tx: Transaction, script: Script, messageTransformer: (hash: string) => BytesLike): Promise<Transaction>;
|
|
52
|
+
_signPWLockScriptForTransaction(tx: Transaction, script: Script, messageTransformer: (hash: string) => BytesLike): Promise<Transaction>;
|
|
53
|
+
_signPersonalEvmForTransaction(tx: Transaction, script: Script, messageTransformer: (hash: string) => BytesLike, hasher?: Hasher): Promise<{
|
|
54
|
+
signature: Bytes;
|
|
55
|
+
position: number;
|
|
56
|
+
} | undefined>;
|
|
48
57
|
}
|
|
49
58
|
//# sourceMappingURL=signerEvm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signerEvm.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,SAAS,EAA0B,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"signerEvm.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,MAAM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O,CAAC,WAAW,CAAC;IA2BjB,+BAA+B,CACnC,EAAE,EAAE,WAAW,EACf,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAC9C,OAAO,CAAC,WAAW,CAAC;IAkBjB,8BAA8B,CAClC,EAAE,EAAE,WAAW,EACf,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,EAC/C,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC;QAAE,SAAS,EAAE,KAAK,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CAe/D"}
|
|
@@ -2,6 +2,7 @@ import { Address } from "../../address/index.js";
|
|
|
2
2
|
import { bytesConcat, bytesFrom } from "../../bytes/index.js";
|
|
3
3
|
import { Transaction, WitnessArgs, } from "../../ckb/index.js";
|
|
4
4
|
import { KnownScript } from "../../client/index.js";
|
|
5
|
+
import { HasherKeecak256 } from "../../hasher/index.js";
|
|
5
6
|
import { hexFrom } from "../../hex/index.js";
|
|
6
7
|
import { numToBytes } from "../../num/index.js";
|
|
7
8
|
import { reduceAsync } from "../../utils/index.js";
|
|
@@ -32,10 +33,24 @@ export class SignerEvm extends Signer {
|
|
|
32
33
|
*/
|
|
33
34
|
async getAddressObjs() {
|
|
34
35
|
const account = await this.getEvmAccount();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
];
|
|
36
|
+
const addresses = await Promise.all([
|
|
37
|
+
this._getOmniLockAddresses(account),
|
|
38
|
+
this._getPWLockAddresses(account),
|
|
39
|
+
]);
|
|
40
|
+
return addresses.flat();
|
|
41
|
+
}
|
|
42
|
+
_getOmniLockAddresses(account) {
|
|
43
|
+
return Promise.all([
|
|
44
|
+
this._getOmniLockEvmAddressObj(account),
|
|
45
|
+
this._getOmniLockOldEvmAddressObj(account),
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
async _getPWLockAddresses(account) {
|
|
49
|
+
const addr = await this._getPWLockEvmAddressObj(account);
|
|
50
|
+
if (!addr) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
return [addr];
|
|
39
54
|
}
|
|
40
55
|
async _getOmniLockEvmAddressObj(account) {
|
|
41
56
|
return Address.fromKnownScript(this.client, KnownScript.OmniLock, hexFrom([0x12, ...bytesFrom(account), 0x00]));
|
|
@@ -43,6 +58,13 @@ export class SignerEvm extends Signer {
|
|
|
43
58
|
async _getOmniLockOldEvmAddressObj(account) {
|
|
44
59
|
return Address.fromKnownScript(this.client, KnownScript.OmniLock, hexFrom([0x1, ...bytesFrom(account), 0x00]));
|
|
45
60
|
}
|
|
61
|
+
async _getPWLockEvmAddressObj(account) {
|
|
62
|
+
try {
|
|
63
|
+
return Address.fromKnownScript(this.client, KnownScript.PWLock, hexFrom(bytesFrom(account)));
|
|
64
|
+
}
|
|
65
|
+
catch { }
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
46
68
|
/**
|
|
47
69
|
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
48
70
|
*
|
|
@@ -51,8 +73,17 @@ export class SignerEvm extends Signer {
|
|
|
51
73
|
*/
|
|
52
74
|
async prepareTransaction(txLike) {
|
|
53
75
|
const tx = Transaction.from(txLike);
|
|
54
|
-
await tx.
|
|
55
|
-
|
|
76
|
+
if ((await tx.findInputIndexByLockId(await this.client.getKnownScript(KnownScript.OmniLock), this.client)) !== undefined) {
|
|
77
|
+
await tx.addCellDepsOfKnownScripts(this.client, KnownScript.OmniLock);
|
|
78
|
+
}
|
|
79
|
+
if ((await tx.findInputIndexByLockId(await this.client.getKnownScript(KnownScript.PWLock), this.client)) !== undefined) {
|
|
80
|
+
await tx.addCellDepsOfKnownScripts(this.client, KnownScript.PWLock);
|
|
81
|
+
}
|
|
82
|
+
const account = await this.getEvmAccount();
|
|
83
|
+
const omniLockAddresses = await this._getOmniLockAddresses(account);
|
|
84
|
+
const pwLockAddresses = await this._getPWLockAddresses(account);
|
|
85
|
+
const omniTx = reduceAsync(omniLockAddresses, (tx, { script }) => tx.prepareSighashAllWitness(script, 85, this.client), tx);
|
|
86
|
+
return reduceAsync(pwLockAddresses, (tx, { script }) => tx.prepareSighashAllWitness(script, 65, this.client), omniTx);
|
|
56
87
|
}
|
|
57
88
|
/**
|
|
58
89
|
* Signs a transaction without modifying it.
|
|
@@ -67,20 +98,41 @@ export class SignerEvm extends Signer {
|
|
|
67
98
|
const { script: oldEvmScript } = await this._getOmniLockOldEvmAddressObj(account);
|
|
68
99
|
tx = await this._signOmniLockScriptForTransaction(tx, evmScript, (hash) => `CKB transaction: ${hash}`);
|
|
69
100
|
tx = await this._signOmniLockScriptForTransaction(tx, oldEvmScript, (hash) => bytesFrom(hash));
|
|
101
|
+
const pwAddress = await this._getPWLockEvmAddressObj(account);
|
|
102
|
+
if (pwAddress) {
|
|
103
|
+
tx = await this._signPWLockScriptForTransaction(tx, pwAddress.script, (hash) => bytesFrom(hash));
|
|
104
|
+
}
|
|
70
105
|
return tx;
|
|
71
106
|
}
|
|
72
107
|
async _signOmniLockScriptForTransaction(tx, script, messageTransformer) {
|
|
73
|
-
const info = await
|
|
108
|
+
const info = await this._signPersonalEvmForTransaction(tx, script, messageTransformer);
|
|
74
109
|
if (!info) {
|
|
75
110
|
return tx;
|
|
76
111
|
}
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
112
|
+
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
113
|
+
witness.lock = hexFrom(bytesConcat(numToBytes(5 * 4 + info.signature.length, 4), numToBytes(4 * 4, 4), numToBytes(5 * 4 + info.signature.length, 4), numToBytes(5 * 4 + info.signature.length, 4), numToBytes(info.signature.length, 4), info.signature));
|
|
114
|
+
tx.setWitnessArgsAt(info.position, witness);
|
|
115
|
+
return tx;
|
|
116
|
+
}
|
|
117
|
+
async _signPWLockScriptForTransaction(tx, script, messageTransformer) {
|
|
118
|
+
const info = await this._signPersonalEvmForTransaction(tx, script, messageTransformer, new HasherKeecak256());
|
|
119
|
+
if (!info) {
|
|
120
|
+
return tx;
|
|
80
121
|
}
|
|
81
122
|
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
82
|
-
witness.lock = hexFrom(
|
|
123
|
+
witness.lock = hexFrom(info.signature);
|
|
83
124
|
tx.setWitnessArgsAt(info.position, witness);
|
|
84
125
|
return tx;
|
|
85
126
|
}
|
|
127
|
+
async _signPersonalEvmForTransaction(tx, script, messageTransformer, hasher) {
|
|
128
|
+
const info = await tx.getSignHashInfo(script, this.client, hasher);
|
|
129
|
+
if (!info) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const signature = bytesFrom(await this.signMessageRaw(messageTransformer(info.message)));
|
|
133
|
+
if (signature[signature.length - 1] >= 27) {
|
|
134
|
+
signature[signature.length - 1] -= 27;
|
|
135
|
+
}
|
|
136
|
+
return { signature, position: info.position };
|
|
137
|
+
}
|
|
86
138
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/signer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAOzC,oBAAY,cAAc;IACxB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,KAAK,UAAU;IACf,UAAU,eAAe;IACzB,YAAY,iBAAiB;CAC9B;AAED;;GAEG;AACH,oBAAY,UAAU;IACpB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nB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -71,6 +71,6 @@ export declare function reduceAsync<T, V>(values: T[], accumulator: (a: T, b: T)
|
|
|
71
71
|
* @param init - The initial value.
|
|
72
72
|
* @returns The accumulated result.
|
|
73
73
|
*/
|
|
74
|
-
export declare function reduceAsync<T, V>(values: V[], accumulator: (a: T, b: V, i: number, values: V[]) => Promise<T | undefined | null | void> | T | undefined | null | void, init: T): Promise<T>;
|
|
74
|
+
export declare function reduceAsync<T, V>(values: V[], accumulator: (a: T, b: V, i: number, values: V[]) => Promise<T | undefined | null | void> | T | undefined | null | void, init: T | Promise<T>): Promise<T>;
|
|
75
75
|
export declare function isWebview(userAgent: string): boolean;
|
|
76
76
|
//# sourceMappingURL=index.d.ts.map
|