@ckb-ccc/core 0.0.4-alpha.6 → 0.0.4
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/signer/btc/signerBtcPublicKeyReadonly.d.ts +12 -0
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
- package/dist/signer/btc/signerBtcPublicKeyReadonly.js +16 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +12 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist/signer/ckb/signerCkbScriptReadonly.js +16 -0
- package/dist/signer/evm/signerEvm.d.ts +5 -1
- package/dist/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist/signer/evm/signerEvm.js +20 -6
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts +13 -1
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
- package/dist/signer/evm/signerEvmAddressReadonly.js +16 -0
- package/dist/signer/helpers.d.ts.map +1 -1
- package/dist/signer/helpers.js +4 -3
- package/dist/signer/signer.d.ts +16 -4
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +5 -2
- package/dist.commonjs/address/address.advanced.d.ts +65 -0
- package/dist.commonjs/address/address.advanced.d.ts.map +1 -0
- package/dist.commonjs/address/address.advanced.js +149 -0
- package/dist.commonjs/address/advanced.d.ts +2 -0
- package/dist.commonjs/address/advanced.d.ts.map +1 -0
- package/dist.commonjs/address/advanced.js +17 -0
- package/dist.commonjs/address/index.d.ts +54 -0
- package/dist.commonjs/address/index.d.ts.map +1 -0
- package/dist.commonjs/address/index.js +84 -0
- package/dist.commonjs/advanced.d.ts +3 -0
- package/dist.commonjs/advanced.d.ts.map +1 -0
- package/dist.commonjs/advanced.js +31 -0
- package/dist.commonjs/advancedBarrel.d.ts +5 -0
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.js +20 -0
- package/dist.commonjs/barrel.d.ts +11 -0
- package/dist.commonjs/barrel.d.ts.map +1 -0
- package/dist.commonjs/barrel.js +26 -0
- package/dist.commonjs/bytes/advanced.d.ts +5 -0
- package/dist.commonjs/bytes/advanced.d.ts.map +1 -0
- package/dist.commonjs/bytes/advanced.js +2 -0
- package/dist.commonjs/bytes/index.d.ts +64 -0
- package/dist.commonjs/bytes/index.d.ts.map +1 -0
- package/dist.commonjs/bytes/index.js +97 -0
- package/dist.commonjs/ckb/advanced.d.ts +4 -0
- package/dist.commonjs/ckb/advanced.d.ts.map +1 -0
- package/dist.commonjs/ckb/advanced.js +32 -0
- package/dist.commonjs/ckb/index.d.ts +3 -0
- package/dist.commonjs/ckb/index.d.ts.map +1 -0
- package/dist.commonjs/ckb/index.js +18 -0
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +355 -0
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts.map +1 -0
- package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -0
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts +6 -0
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts.map +1 -0
- package/dist.commonjs/ckb/molecule.advanced/index.js +25 -0
- package/dist.commonjs/ckb/script.advanced.d.ts +5 -0
- package/dist.commonjs/ckb/script.advanced.d.ts.map +1 -0
- package/dist.commonjs/ckb/script.advanced.js +16 -0
- package/dist.commonjs/ckb/script.d.ts +126 -0
- package/dist.commonjs/ckb/script.d.ts.map +1 -0
- package/dist.commonjs/ckb/script.js +188 -0
- package/dist.commonjs/ckb/transaction.advanced.d.ts +5 -0
- package/dist.commonjs/ckb/transaction.advanced.d.ts.map +1 -0
- package/dist.commonjs/ckb/transaction.advanced.js +12 -0
- package/dist.commonjs/ckb/transaction.d.ts +533 -0
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -0
- package/dist.commonjs/ckb/transaction.js +665 -0
- package/dist.commonjs/client/advanced.d.ts +4 -0
- package/dist.commonjs/client/advanced.d.ts.map +1 -0
- package/dist.commonjs/client/advanced.js +19 -0
- package/dist.commonjs/client/client.d.ts +19 -0
- package/dist.commonjs/client/client.d.ts.map +1 -0
- package/dist.commonjs/client/client.js +30 -0
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +4 -0
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +26 -0
- package/dist.commonjs/client/clientPublicMainnet.d.ts +9 -0
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicMainnet.js +17 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +4 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +26 -0
- package/dist.commonjs/client/clientPublicTestnet.d.ts +9 -0
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicTestnet.js +17 -0
- package/dist.commonjs/client/clientTypes.d.ts +8 -0
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -0
- package/dist.commonjs/client/clientTypes.js +2 -0
- package/dist.commonjs/client/index.d.ts +6 -0
- package/dist.commonjs/client/index.d.ts.map +1 -0
- package/dist.commonjs/client/index.js +21 -0
- package/dist.commonjs/client/jsonRpc/advanced.d.ts +3 -0
- package/dist.commonjs/client/jsonRpc/advanced.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/advanced.js +18 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts +68 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/index.js +128 -0
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +28 -0
- package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/transformers.js +126 -0
- package/dist.commonjs/client/jsonRpc/types.d.ts +41 -0
- package/dist.commonjs/client/jsonRpc/types.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/types.js +2 -0
- package/dist.commonjs/fixedPoint/index.d.ts +49 -0
- package/dist.commonjs/fixedPoint/index.d.ts.map +1 -0
- package/dist.commonjs/fixedPoint/index.js +65 -0
- package/dist.commonjs/hasher/advanced.d.ts +2 -0
- package/dist.commonjs/hasher/advanced.d.ts.map +1 -0
- package/dist.commonjs/hasher/advanced.js +4 -0
- package/dist.commonjs/hasher/index.d.ts +52 -0
- package/dist.commonjs/hasher/index.d.ts.map +1 -0
- package/dist.commonjs/hasher/index.js +68 -0
- package/dist.commonjs/hex/index.d.ts +24 -0
- package/dist.commonjs/hex/index.d.ts.map +1 -0
- package/dist.commonjs/hex/index.js +20 -0
- package/dist.commonjs/index.d.ts +3 -0
- package/dist.commonjs/index.d.ts.map +1 -0
- package/dist.commonjs/index.js +31 -0
- package/dist.commonjs/num/index.d.ts +112 -0
- package/dist.commonjs/num/index.d.ts.map +1 -0
- package/dist.commonjs/num/index.js +139 -0
- package/dist.commonjs/signer/btc/index.d.ts +3 -0
- package/dist.commonjs/signer/btc/index.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/index.js +18 -0
- package/dist.commonjs/signer/btc/signerBtc.d.ts +50 -0
- package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/signerBtc.js +71 -0
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +60 -0
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +72 -0
- package/dist.commonjs/signer/ckb/index.d.ts +2 -0
- package/dist.commonjs/signer/ckb/index.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/index.js +17 -0
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +59 -0
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +71 -0
- package/dist.commonjs/signer/evm/index.d.ts +3 -0
- package/dist.commonjs/signer/evm/index.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/index.js +18 -0
- package/dist.commonjs/signer/evm/signerEvm.d.ts +46 -0
- package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/signerEvm.js +83 -0
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +52 -0
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +62 -0
- package/dist.commonjs/signer/helpers.d.ts +40 -0
- package/dist.commonjs/signer/helpers.d.ts.map +1 -0
- package/dist.commonjs/signer/helpers.js +96 -0
- package/dist.commonjs/signer/index.d.ts +6 -0
- package/dist.commonjs/signer/index.d.ts.map +1 -0
- package/dist.commonjs/signer/index.js +21 -0
- package/dist.commonjs/signer/signer.d.ts +125 -0
- package/dist.commonjs/signer/signer.d.ts.map +1 -0
- package/dist.commonjs/signer/signer.js +109 -0
- package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +1 -0
- package/dist.commonjs/utils/index.d.ts +7 -0
- package/dist.commonjs/utils/index.d.ts.map +1 -0
- package/dist.commonjs/utils/index.js +10 -0
- package/package.json +20 -7
- package/src/signer/btc/signerBtcPublicKeyReadonly.ts +18 -0
- package/src/signer/ckb/signerCkbScriptReadonly.ts +18 -0
- package/src/signer/evm/signerEvm.ts +55 -12
- package/src/signer/evm/signerEvmAddressReadonly.ts +19 -1
- package/src/signer/helpers.ts +6 -4
- package/src/signer/signer.ts +20 -3
- package/tsconfig.base.json +21 -0
- package/tsconfig.commonjs.json +8 -0
|
@@ -16,12 +16,24 @@ export declare class SignerBtcPublicKeyReadonly extends SignerBtc {
|
|
|
16
16
|
* @param publicKey - The public key associated with the signer.
|
|
17
17
|
*/
|
|
18
18
|
constructor(client: Client, account: string, publicKey: HexLike);
|
|
19
|
+
/**
|
|
20
|
+
* Construct a new signer with the client replaced.
|
|
21
|
+
*
|
|
22
|
+
* @returns A promise that resolves the new Signer.
|
|
23
|
+
*/
|
|
24
|
+
replaceClient(client: Client): Promise<SignerBtcPublicKeyReadonly>;
|
|
19
25
|
/**
|
|
20
26
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
21
27
|
*
|
|
22
28
|
* @returns A promise that resolves when the connection is complete.
|
|
23
29
|
*/
|
|
24
30
|
connect(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Check if the signer is connected.
|
|
33
|
+
*
|
|
34
|
+
* @returns A promise that resolves the connection status.
|
|
35
|
+
*/
|
|
36
|
+
isConnected(): Promise<boolean>;
|
|
25
37
|
/**
|
|
26
38
|
* Gets the Bitcoin account associated with the signer.
|
|
27
39
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signerBtcPublicKeyReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtcPublicKeyReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,SAAS;IAYrD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAX1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAM;IAEhC;;;;;;OAMG;gBAED,MAAM,EAAE,MAAM,EACG,OAAO,EAAE,MAAM,EAChC,SAAS,EAAE,OAAO;IAOpB;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;;;;;;OASG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC;;;;;;;;;OASG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC;CAGtC"}
|
|
1
|
+
{"version":3,"file":"signerBtcPublicKeyReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtcPublicKeyReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,SAAS;IAYrD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAX1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAM;IAEhC;;;;;;OAMG;gBAED,MAAM,EAAE,MAAM,EACG,OAAO,EAAE,MAAM,EAChC,SAAS,EAAE,OAAO;IAOpB;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAIxE;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;OASG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC;;;;;;;;;OASG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC;CAGtC"}
|
|
@@ -17,12 +17,28 @@ export class SignerBtcPublicKeyReadonly extends SignerBtc {
|
|
|
17
17
|
this.account = account;
|
|
18
18
|
this.publicKey = hexFrom(publicKey);
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Construct a new signer with the client replaced.
|
|
22
|
+
*
|
|
23
|
+
* @returns A promise that resolves the new Signer.
|
|
24
|
+
*/
|
|
25
|
+
async replaceClient(client) {
|
|
26
|
+
return new SignerBtcPublicKeyReadonly(client, this.account, this.publicKey);
|
|
27
|
+
}
|
|
20
28
|
/**
|
|
21
29
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
22
30
|
*
|
|
23
31
|
* @returns A promise that resolves when the connection is complete.
|
|
24
32
|
*/
|
|
25
33
|
async connect() { }
|
|
34
|
+
/**
|
|
35
|
+
* Check if the signer is connected.
|
|
36
|
+
*
|
|
37
|
+
* @returns A promise that resolves the connection status.
|
|
38
|
+
*/
|
|
39
|
+
async isConnected() {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
26
42
|
/**
|
|
27
43
|
* Gets the Bitcoin account associated with the signer.
|
|
28
44
|
*
|
|
@@ -15,12 +15,24 @@ export declare class SignerCkbScriptReadonly extends Signer {
|
|
|
15
15
|
* @param script - The script associated with the signer.
|
|
16
16
|
*/
|
|
17
17
|
constructor(client: Client, script: ScriptLike);
|
|
18
|
+
/**
|
|
19
|
+
* Construct a new signer with the client replaced.
|
|
20
|
+
*
|
|
21
|
+
* @returns A promise that resolves the new Signer.
|
|
22
|
+
*/
|
|
23
|
+
replaceClient(client: Client): Promise<SignerCkbScriptReadonly>;
|
|
18
24
|
/**
|
|
19
25
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
20
26
|
*
|
|
21
27
|
* @returns A promise that resolves when the connection is complete.
|
|
22
28
|
*/
|
|
23
29
|
connect(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Check if the signer is connected.
|
|
32
|
+
*
|
|
33
|
+
* @returns A promise that resolves the connection status.
|
|
34
|
+
*/
|
|
35
|
+
isConnected(): Promise<boolean>;
|
|
24
36
|
/**
|
|
25
37
|
* Gets the internal address for the script.
|
|
26
38
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signerCkbScriptReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/signerCkbScriptReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAU,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,MAAM;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAM9C;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;;;;;;OASG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;;;;;;OASG;IAEG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG3C"}
|
|
1
|
+
{"version":3,"file":"signerCkbScriptReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/signerCkbScriptReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAU,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,MAAM;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAM9C;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAIrE;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;OASG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;;;;;;OASG;IAEG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG3C"}
|
|
@@ -16,12 +16,28 @@ export class SignerCkbScriptReadonly extends Signer {
|
|
|
16
16
|
super(client);
|
|
17
17
|
this.script = Script.from(script);
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Construct a new signer with the client replaced.
|
|
21
|
+
*
|
|
22
|
+
* @returns A promise that resolves the new Signer.
|
|
23
|
+
*/
|
|
24
|
+
async replaceClient(client) {
|
|
25
|
+
return new SignerCkbScriptReadonly(client, this.script);
|
|
26
|
+
}
|
|
19
27
|
/**
|
|
20
28
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
21
29
|
*
|
|
22
30
|
* @returns A promise that resolves when the connection is complete.
|
|
23
31
|
*/
|
|
24
32
|
async connect() { }
|
|
33
|
+
/**
|
|
34
|
+
* Check if the signer is connected.
|
|
35
|
+
*
|
|
36
|
+
* @returns A promise that resolves the connection status.
|
|
37
|
+
*/
|
|
38
|
+
async isConnected() {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
25
41
|
/**
|
|
26
42
|
* Gets the internal address for the script.
|
|
27
43
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Address } from "../../address";
|
|
2
|
-
import {
|
|
2
|
+
import { BytesLike } from "../../bytes";
|
|
3
|
+
import { Script, Transaction, TransactionLike } from "../../ckb";
|
|
3
4
|
import { Signer } from "../signer";
|
|
4
5
|
/**
|
|
5
6
|
* An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
|
|
@@ -24,6 +25,8 @@ export declare abstract class SignerEvm extends Signer {
|
|
|
24
25
|
* @returns A promise that resolves to an array of Address objects.
|
|
25
26
|
*/
|
|
26
27
|
getAddressObjs(): Promise<Address[]>;
|
|
28
|
+
_getOmniLockEvmAddressObj(account: string): Promise<Address>;
|
|
29
|
+
_getOmniLockOldEvmAddressObj(account: string): Promise<Address>;
|
|
27
30
|
/**
|
|
28
31
|
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
29
32
|
*
|
|
@@ -38,5 +41,6 @@ export declare abstract class SignerEvm extends Signer {
|
|
|
38
41
|
* @returns A promise that resolves to a signed Transaction object.
|
|
39
42
|
*/
|
|
40
43
|
signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
|
|
44
|
+
_signOmniLockScriptForTransaction(tx: Transaction, script: Script, messageTransformer: (hash: string) => BytesLike): Promise<Transaction>;
|
|
41
45
|
}
|
|
42
46
|
//# 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,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"signerEvm.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAA0B,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAK9E,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;GAGG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAQpC,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ5D,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQrE;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAYvE;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAsBlE,iCAAiC,CACrC,EAAE,EAAE,WAAW,EACf,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAC9C,OAAO,CAAC,WAAW,CAAC;CA6BxB"}
|
|
@@ -27,9 +27,16 @@ export class SignerEvm extends Signer {
|
|
|
27
27
|
async getAddressObjs() {
|
|
28
28
|
const account = await this.getEvmAccount();
|
|
29
29
|
return [
|
|
30
|
-
await
|
|
30
|
+
await this._getOmniLockEvmAddressObj(account),
|
|
31
|
+
await this._getOmniLockOldEvmAddressObj(account),
|
|
31
32
|
];
|
|
32
33
|
}
|
|
34
|
+
async _getOmniLockEvmAddressObj(account) {
|
|
35
|
+
return Address.fromKnownScript(KnownScript.OmniLock, hexFrom([0x12, ...bytesFrom(account), 0x00]), this.client);
|
|
36
|
+
}
|
|
37
|
+
async _getOmniLockOldEvmAddressObj(account) {
|
|
38
|
+
return Address.fromKnownScript(KnownScript.OmniLock, hexFrom([0x1, ...bytesFrom(account), 0x00]), this.client);
|
|
39
|
+
}
|
|
33
40
|
/**
|
|
34
41
|
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
35
42
|
*
|
|
@@ -37,8 +44,8 @@ export class SignerEvm extends Signer {
|
|
|
37
44
|
* @returns A promise that resolves to the prepared Transaction object.
|
|
38
45
|
*/
|
|
39
46
|
async prepareTransaction(txLike) {
|
|
40
|
-
const
|
|
41
|
-
return prepareSighashAllWitness(
|
|
47
|
+
const addresses = await this.getAddressObjs();
|
|
48
|
+
return addresses.reduce((txPromise, { script }) => txPromise.then((tx) => prepareSighashAllWitness(tx, script, 85, this.client)), Promise.resolve(Transaction.from(txLike)));
|
|
42
49
|
}
|
|
43
50
|
/**
|
|
44
51
|
* Signs a transaction without modifying it.
|
|
@@ -47,13 +54,20 @@ export class SignerEvm extends Signer {
|
|
|
47
54
|
* @returns A promise that resolves to a signed Transaction object.
|
|
48
55
|
*/
|
|
49
56
|
async signOnlyTransaction(txLike) {
|
|
50
|
-
|
|
51
|
-
const
|
|
57
|
+
let tx = Transaction.from(txLike);
|
|
58
|
+
const account = await this.getEvmAccount();
|
|
59
|
+
const { script: evmScript } = await this._getOmniLockEvmAddressObj(account);
|
|
60
|
+
const { script: oldEvmScript } = await this._getOmniLockOldEvmAddressObj(account);
|
|
61
|
+
tx = await this._signOmniLockScriptForTransaction(tx, evmScript, (hash) => `CKB transaction: ${hash}`);
|
|
62
|
+
tx = await this._signOmniLockScriptForTransaction(tx, oldEvmScript, (hash) => bytesFrom(hash));
|
|
63
|
+
return tx;
|
|
64
|
+
}
|
|
65
|
+
async _signOmniLockScriptForTransaction(tx, script, messageTransformer) {
|
|
52
66
|
const info = await getSignHashInfo(tx, script, this.client);
|
|
53
67
|
if (!info) {
|
|
54
68
|
return tx;
|
|
55
69
|
}
|
|
56
|
-
const signature = bytesFrom(await this.signMessage(
|
|
70
|
+
const signature = bytesFrom(await this.signMessage(messageTransformer(info.message)));
|
|
57
71
|
if (signature[signature.length - 1] >= 27) {
|
|
58
72
|
signature[signature.length - 1] -= 27;
|
|
59
73
|
}
|
|
@@ -5,7 +5,7 @@ import { SignerEvm } from "./signerEvm";
|
|
|
5
5
|
* A class extending SignerEvm that provides read-only access to an EVM address.
|
|
6
6
|
* This class does not support signing operations.
|
|
7
7
|
*/
|
|
8
|
-
export declare
|
|
8
|
+
export declare class SignerEvmAddressReadonly extends SignerEvm {
|
|
9
9
|
private readonly address;
|
|
10
10
|
/**
|
|
11
11
|
* Creates an instance of SignerEvmAddressReadonly.
|
|
@@ -14,6 +14,12 @@ export declare abstract class SignerEvmAddressReadonly extends SignerEvm {
|
|
|
14
14
|
* @param address - The EVM address associated with the signer.
|
|
15
15
|
*/
|
|
16
16
|
constructor(client: Client, address: HexLike);
|
|
17
|
+
/**
|
|
18
|
+
* Construct a new signer with the client replaced.
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise that resolves the new Signer.
|
|
21
|
+
*/
|
|
22
|
+
replaceClient(client: Client): Promise<SignerEvmAddressReadonly>;
|
|
17
23
|
/**
|
|
18
24
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
19
25
|
*
|
|
@@ -25,6 +31,12 @@ export declare abstract class SignerEvmAddressReadonly extends SignerEvm {
|
|
|
25
31
|
* ```
|
|
26
32
|
*/
|
|
27
33
|
connect(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Check if the signer is connected.
|
|
36
|
+
*
|
|
37
|
+
* @returns A promise that resolves the connection status.
|
|
38
|
+
*/
|
|
39
|
+
isConnected(): Promise<boolean>;
|
|
28
40
|
/**
|
|
29
41
|
* Gets the EVM account associated with the signer.
|
|
30
42
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signerEvmAddressReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvmAddressReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAO,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"signerEvmAddressReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvmAddressReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAO,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;IAE9B;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAM5C;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAItE;;;;;;;;;OASG;IAEG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;OASG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAGvC"}
|
|
@@ -15,6 +15,14 @@ export class SignerEvmAddressReadonly extends SignerEvm {
|
|
|
15
15
|
super(client);
|
|
16
16
|
this.address = hexFrom(address);
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Construct a new signer with the client replaced.
|
|
20
|
+
*
|
|
21
|
+
* @returns A promise that resolves the new Signer.
|
|
22
|
+
*/
|
|
23
|
+
async replaceClient(client) {
|
|
24
|
+
return new SignerEvmAddressReadonly(client, this.address);
|
|
25
|
+
}
|
|
18
26
|
/**
|
|
19
27
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
20
28
|
*
|
|
@@ -26,6 +34,14 @@ export class SignerEvmAddressReadonly extends SignerEvm {
|
|
|
26
34
|
* ```
|
|
27
35
|
*/
|
|
28
36
|
async connect() { }
|
|
37
|
+
/**
|
|
38
|
+
* Check if the signer is connected.
|
|
39
|
+
*
|
|
40
|
+
* @returns A promise that resolves the connection status.
|
|
41
|
+
*/
|
|
42
|
+
async isConnected() {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
29
45
|
/**
|
|
30
46
|
* Gets the EVM account associated with the signer.
|
|
31
47
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/signer/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,WAAW,EACX,eAAe,EAEhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,GAAG,EAAW,MAAM,QAAQ,CAAC;AAEtC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAuCzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/signer/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,WAAW,EACX,eAAe,EAEhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,GAAG,EAAW,MAAM,QAAQ,CAAC;AAEtC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAuCzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,CA+BtB"}
|
package/dist/signer/helpers.js
CHANGED
|
@@ -32,7 +32,7 @@ export async function getSignHashInfo(txLike, scriptLike, client) {
|
|
|
32
32
|
throw Error("Unable to resolve inputs info");
|
|
33
33
|
}
|
|
34
34
|
if (!script.eq(input.cellOutput.lock)) {
|
|
35
|
-
|
|
35
|
+
continue;
|
|
36
36
|
}
|
|
37
37
|
if (position === -1) {
|
|
38
38
|
position = i;
|
|
@@ -81,8 +81,9 @@ export async function prepareSighashAllWitness(txLike, scriptLike, lockLen, clie
|
|
|
81
81
|
if (position === -1) {
|
|
82
82
|
return tx;
|
|
83
83
|
}
|
|
84
|
-
const
|
|
85
|
-
|
|
84
|
+
const rawWitness = tx.witnesses[position];
|
|
85
|
+
const witness = (rawWitness ?? "0x") !== "0x"
|
|
86
|
+
? WitnessArgs.fromBytes(rawWitness)
|
|
86
87
|
: WitnessArgs.from({});
|
|
87
88
|
witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
|
|
88
89
|
tx.witnesses[position] = hexFrom(witness.toBytes());
|
package/dist/signer/signer.d.ts
CHANGED
|
@@ -8,14 +8,27 @@ import { Hex } from "../hex";
|
|
|
8
8
|
* This class provides methods to connect, get addresses, and sign transactions.
|
|
9
9
|
*/
|
|
10
10
|
export declare abstract class Signer {
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
11
|
+
protected client_: Client;
|
|
12
|
+
constructor(client_: Client);
|
|
13
|
+
get client(): Client;
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
+
* Construct a new signer with the client replaced.
|
|
16
|
+
*
|
|
17
|
+
* @returns A promise that resolves the new Signer.
|
|
18
|
+
*/
|
|
19
|
+
abstract replaceClient(client: Client): Promise<Signer>;
|
|
20
|
+
/**
|
|
21
|
+
* Connects to the signer.
|
|
15
22
|
*
|
|
16
23
|
* @returns A promise that resolves when the connection is complete.
|
|
17
24
|
*/
|
|
18
25
|
abstract connect(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Check if the signer is connected.
|
|
28
|
+
*
|
|
29
|
+
* @returns A promise that resolves the connection status.
|
|
30
|
+
*/
|
|
31
|
+
abstract isConnected(): Promise<boolean>;
|
|
19
32
|
/**
|
|
20
33
|
* Gets the internal address associated with the signer.
|
|
21
34
|
*
|
|
@@ -108,6 +121,5 @@ export declare class SignerInfo {
|
|
|
108
121
|
export type Wallet = {
|
|
109
122
|
name: string;
|
|
110
123
|
icon: string;
|
|
111
|
-
signers: SignerInfo[];
|
|
112
124
|
};
|
|
113
125
|
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B;;;GAGG;AACH,8BAAsB,MAAM;
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B;;;GAGG;AACH,8BAAsB,MAAM;IACd,SAAS,CAAC,OAAO,EAAE,MAAM;gBAAf,OAAO,EAAE,MAAM;IAErC,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAEvD;;;;OAIG;IACH,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAEjC;;;;OAIG;IACH,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAExC;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAE9C;;;;OAIG;IACH,QAAQ,CAAC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAE7C;;;;;OAKG;IACG,wBAAwB,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvE;;;;;OAKG;IACG,qBAAqB,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlE;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAMvC;;;;;;OAMG;IACH,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAInD;;;;;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,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED;;GAEG;AACH,qBAAa,UAAU;IAEZ,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,MAAM;gBADd,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM;CAExB;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
package/dist/signer/signer.js
CHANGED
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
* This class provides methods to connect, get addresses, and sign transactions.
|
|
4
4
|
*/
|
|
5
5
|
export class Signer {
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
6
|
+
constructor(client_) {
|
|
7
|
+
this.client_ = client_;
|
|
8
|
+
}
|
|
9
|
+
get client() {
|
|
10
|
+
return this.client_;
|
|
8
11
|
}
|
|
9
12
|
/**
|
|
10
13
|
* Gets the recommended Address object for the signer.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Client } from "../client";
|
|
2
|
+
import { type AddressLike } from "./index";
|
|
3
|
+
/**
|
|
4
|
+
* Parses an address string into an address information object.
|
|
5
|
+
*
|
|
6
|
+
* @param address - The address string to parse.
|
|
7
|
+
* @returns An object containing the address prefix, address format, and payload array.
|
|
8
|
+
*
|
|
9
|
+
* @throws Will throw an error if the address format is unknown.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const addressInfo = addressPayloadFromString("ckt1112139193129");
|
|
14
|
+
* console.log(addressInfo.prefix); // Outputs the address prefix
|
|
15
|
+
* console.log(addressInfo.format); // Outputs the address format
|
|
16
|
+
* console.log(addressInfo.payload); // Outputs the payload array
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function addressPayloadFromString(address: string): {
|
|
20
|
+
prefix: string;
|
|
21
|
+
format: AddressFormat;
|
|
22
|
+
payload: number[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Converts an address payload into an address-like object.
|
|
26
|
+
*
|
|
27
|
+
* @param prefix - The address prefix.
|
|
28
|
+
* @param format - The format of the address, as defined by the AddressFormat enum.
|
|
29
|
+
* @param payload - The payload array containing the address data.
|
|
30
|
+
* @param client - The client instance used to fetch known scripts.
|
|
31
|
+
* @returns A promise that resolves to an AddressLike object.
|
|
32
|
+
*
|
|
33
|
+
* @throws Will throw an error if the payload length is insufficient or if the script type is unknown.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const address = await addressFromPayload("ckt", AddressFormat.Full, [/* payload data *\/], client);
|
|
38
|
+
* console.log(address.script); // Outputs the script object
|
|
39
|
+
* console.log(address.prefix); // Outputs the address prefix
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function addressFromPayload(prefix: string, format: AddressFormat, payload: number[], client: Client): Promise<AddressLike>;
|
|
43
|
+
export declare enum AddressFormat {
|
|
44
|
+
/**
|
|
45
|
+
* full version identifies the hashType
|
|
46
|
+
*/
|
|
47
|
+
Full = 0,
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated
|
|
50
|
+
* short version for locks with Known codeHash, deprecated
|
|
51
|
+
*/
|
|
52
|
+
Short = 1,
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated
|
|
55
|
+
* full version with hashType = "Data", deprecated
|
|
56
|
+
*/
|
|
57
|
+
FullData = 2,
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated
|
|
60
|
+
* full version with hashType = "Type", deprecated
|
|
61
|
+
*/
|
|
62
|
+
FullType = 4
|
|
63
|
+
}
|
|
64
|
+
export declare const ADDRESS_BECH32_LIMIT = 1023;
|
|
65
|
+
//# sourceMappingURL=address.advanced.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.advanced.d.ts","sourceRoot":"","sources":["../../src/address/address.advanced.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAe,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;;;;;;;;GAeG;AAEH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CA2BA;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,CA4EtB;AAED,oBAAY,aAAa;IACvB;;OAEG;IACH,IAAI,IAAO;IACX;;;OAGG;IACH,KAAK,IAAO;IACZ;;;OAGG;IACH,QAAQ,IAAO;IACf;;;OAGG;IACH,QAAQ,IAAO;CAChB;AAED,eAAO,MAAM,oBAAoB,OAAO,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ADDRESS_BECH32_LIMIT = exports.AddressFormat = exports.addressFromPayload = exports.addressPayloadFromString = void 0;
|
|
4
|
+
const bech32_1 = require("bech32");
|
|
5
|
+
const ckb_1 = require("../ckb");
|
|
6
|
+
const client_1 = require("../client");
|
|
7
|
+
const hex_1 = require("../hex");
|
|
8
|
+
/**
|
|
9
|
+
* Parses an address string into an address information object.
|
|
10
|
+
*
|
|
11
|
+
* @param address - The address string to parse.
|
|
12
|
+
* @returns An object containing the address prefix, address format, and payload array.
|
|
13
|
+
*
|
|
14
|
+
* @throws Will throw an error if the address format is unknown.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const addressInfo = addressPayloadFromString("ckt1112139193129");
|
|
19
|
+
* console.log(addressInfo.prefix); // Outputs the address prefix
|
|
20
|
+
* console.log(addressInfo.format); // Outputs the address format
|
|
21
|
+
* console.log(addressInfo.payload); // Outputs the payload array
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function addressPayloadFromString(address) {
|
|
25
|
+
// Try parse full format address
|
|
26
|
+
{
|
|
27
|
+
const { words, prefix } = bech32_1.bech32m.decode(address, exports.ADDRESS_BECH32_LIMIT);
|
|
28
|
+
const [formatType, ...payload] = bech32_1.bech32m.fromWords(words);
|
|
29
|
+
if (formatType === AddressFormat.Full) {
|
|
30
|
+
return { prefix, format: AddressFormat.Full, payload };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Try parse legacy 2019 format address
|
|
34
|
+
{
|
|
35
|
+
const { prefix, words } = bech32_1.bech32.decode(address, exports.ADDRESS_BECH32_LIMIT);
|
|
36
|
+
const [formatType, ...payload] = bech32_1.bech32.fromWords(words);
|
|
37
|
+
if ([
|
|
38
|
+
AddressFormat.FullData,
|
|
39
|
+
AddressFormat.FullType,
|
|
40
|
+
AddressFormat.Short,
|
|
41
|
+
].includes(formatType)) {
|
|
42
|
+
return { prefix, format: formatType, payload };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw Error(`Unknown address format ${address}`);
|
|
46
|
+
}
|
|
47
|
+
exports.addressPayloadFromString = addressPayloadFromString;
|
|
48
|
+
/**
|
|
49
|
+
* Converts an address payload into an address-like object.
|
|
50
|
+
*
|
|
51
|
+
* @param prefix - The address prefix.
|
|
52
|
+
* @param format - The format of the address, as defined by the AddressFormat enum.
|
|
53
|
+
* @param payload - The payload array containing the address data.
|
|
54
|
+
* @param client - The client instance used to fetch known scripts.
|
|
55
|
+
* @returns A promise that resolves to an AddressLike object.
|
|
56
|
+
*
|
|
57
|
+
* @throws Will throw an error if the payload length is insufficient or if the script type is unknown.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const address = await addressFromPayload("ckt", AddressFormat.Full, [/* payload data *\/], client);
|
|
62
|
+
* console.log(address.script); // Outputs the script object
|
|
63
|
+
* console.log(address.prefix); // Outputs the address prefix
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
async function addressFromPayload(prefix, format, payload, client) {
|
|
67
|
+
if (format === AddressFormat.Full) {
|
|
68
|
+
if (payload.length < 32 + 1) {
|
|
69
|
+
throw new Error(`Invalid full address without enough payload ${(0, hex_1.hexFrom)(payload)}`);
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
script: {
|
|
73
|
+
codeHash: payload.slice(0, 32),
|
|
74
|
+
hashType: (0, ckb_1.hashTypeFromBytes)(payload.slice(32, 33)),
|
|
75
|
+
args: payload.slice(33),
|
|
76
|
+
},
|
|
77
|
+
prefix,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (format === AddressFormat.FullData) {
|
|
81
|
+
if (payload.length < 32) {
|
|
82
|
+
throw new Error(`Invalid full data address without enough payload ${(0, hex_1.hexFrom)(payload)}`);
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
script: {
|
|
86
|
+
codeHash: payload.slice(0, 32),
|
|
87
|
+
hashType: "data",
|
|
88
|
+
args: payload.slice(32),
|
|
89
|
+
},
|
|
90
|
+
prefix,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (format === AddressFormat.FullType) {
|
|
94
|
+
if (payload.length < 32) {
|
|
95
|
+
throw new Error(`Invalid full type address without enough payload ${(0, hex_1.hexFrom)(payload)}`);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
script: {
|
|
99
|
+
codeHash: payload.slice(0, 32),
|
|
100
|
+
hashType: "type",
|
|
101
|
+
args: payload.slice(32),
|
|
102
|
+
},
|
|
103
|
+
prefix,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// format === AddressFormat.Short
|
|
107
|
+
if (payload.length !== 21) {
|
|
108
|
+
throw new Error(`Invalid short address without enough payload ${(0, hex_1.hexFrom)(payload)}`);
|
|
109
|
+
}
|
|
110
|
+
const script = [
|
|
111
|
+
client_1.KnownScript.Secp256k1Blake160,
|
|
112
|
+
client_1.KnownScript.Secp256k1Multisig,
|
|
113
|
+
client_1.KnownScript.AnyoneCanPay,
|
|
114
|
+
][payload[0]];
|
|
115
|
+
if (script === undefined) {
|
|
116
|
+
throw new Error(`Invalid short address with unknown script ${(0, hex_1.hexFrom)(payload)}`);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
script: {
|
|
120
|
+
...(await client.getKnownScript(script)),
|
|
121
|
+
args: payload.slice(1),
|
|
122
|
+
},
|
|
123
|
+
prefix,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
exports.addressFromPayload = addressFromPayload;
|
|
127
|
+
var AddressFormat;
|
|
128
|
+
(function (AddressFormat) {
|
|
129
|
+
/**
|
|
130
|
+
* full version identifies the hashType
|
|
131
|
+
*/
|
|
132
|
+
AddressFormat[AddressFormat["Full"] = 0] = "Full";
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated
|
|
135
|
+
* short version for locks with Known codeHash, deprecated
|
|
136
|
+
*/
|
|
137
|
+
AddressFormat[AddressFormat["Short"] = 1] = "Short";
|
|
138
|
+
/**
|
|
139
|
+
* @deprecated
|
|
140
|
+
* full version with hashType = "Data", deprecated
|
|
141
|
+
*/
|
|
142
|
+
AddressFormat[AddressFormat["FullData"] = 2] = "FullData";
|
|
143
|
+
/**
|
|
144
|
+
* @deprecated
|
|
145
|
+
* full version with hashType = "Type", deprecated
|
|
146
|
+
*/
|
|
147
|
+
AddressFormat[AddressFormat["FullType"] = 4] = "FullType";
|
|
148
|
+
})(AddressFormat || (exports.AddressFormat = AddressFormat = {}));
|
|
149
|
+
exports.ADDRESS_BECH32_LIMIT = 1023;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/address/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./address.advanced"), exports);
|