@ckb-ccc/core 0.0.4-alpha.8 → 0.0.5-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/README.md +6 -0
- package/dist/ckb/transaction.d.ts +85 -2
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +152 -7
- package/dist/client/client.d.ts +8 -3
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +29 -2
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +4 -0
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.js +4 -0
- package/dist/client/clientTypes.d.ts +48 -1
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/clientTypes.js +27 -1
- package/dist/client/jsonRpc/index.d.ts +9 -1
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +15 -1
- package/dist/client/jsonRpc/transformers.d.ts +17 -3
- package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
- package/dist/client/jsonRpc/transformers.js +37 -3
- package/dist/client/jsonRpc/types.d.ts +15 -0
- package/dist/client/jsonRpc/types.d.ts.map +1 -1
- package/dist/fixedPoint/index.d.ts.map +1 -1
- package/dist/fixedPoint/index.js +4 -1
- package/dist/fixedPoint/index.test.d.ts +2 -0
- package/dist/fixedPoint/index.test.d.ts.map +1 -0
- package/dist/fixedPoint/index.test.js +43 -0
- package/dist/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist/signer/btc/signerBtc.js +2 -3
- 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 +21 -8
- 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/index.d.ts +0 -1
- package/dist/signer/index.d.ts.map +1 -1
- package/dist/signer/index.js +0 -1
- package/dist/signer/signer.d.ts +26 -6
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +14 -3
- 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 +616 -0
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -0
- package/dist.commonjs/ckb/transaction.js +810 -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 +24 -0
- package/dist.commonjs/client/client.d.ts.map +1 -0
- package/dist.commonjs/client/client.js +57 -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 +30 -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 +30 -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 +55 -0
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -0
- package/dist.commonjs/client/clientTypes.js +31 -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 +76 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/index.js +142 -0
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +42 -0
- package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/transformers.js +160 -0
- package/dist.commonjs/client/jsonRpc/types.d.ts +56 -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 +68 -0
- package/dist.commonjs/fixedPoint/index.test.d.ts +2 -0
- package/dist.commonjs/fixedPoint/index.test.d.ts.map +1 -0
- package/dist.commonjs/fixedPoint/index.test.js +45 -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 +70 -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 +82 -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/index.d.ts +5 -0
- package/dist.commonjs/signer/index.d.ts.map +1 -0
- package/dist.commonjs/signer/index.js +20 -0
- package/dist.commonjs/signer/signer.d.ts +133 -0
- package/dist.commonjs/signer/signer.d.ts.map +1 -0
- package/dist.commonjs/signer/signer.js +117 -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/jest.config.js +5 -0
- package/package.json +24 -7
- package/src/ckb/transaction.ts +198 -3
- package/src/client/client.ts +64 -3
- package/src/client/clientPublicMainnet.advanced.ts +5 -0
- package/src/client/clientPublicTestnet.advanced.ts +5 -0
- package/src/client/clientTypes.ts +70 -1
- package/src/client/jsonRpc/index.ts +38 -2
- package/src/client/jsonRpc/transformers.ts +73 -4
- package/src/client/jsonRpc/types.ts +16 -0
- package/src/fixedPoint/index.test.ts +55 -0
- package/src/fixedPoint/index.ts +7 -1
- package/src/signer/btc/signerBtc.ts +6 -3
- package/src/signer/btc/signerBtcPublicKeyReadonly.ts +18 -0
- package/src/signer/ckb/signerCkbScriptReadonly.ts +18 -0
- package/src/signer/evm/signerEvm.ts +56 -14
- package/src/signer/evm/signerEvmAddressReadonly.ts +19 -1
- package/src/signer/index.ts +0 -1
- package/src/signer/signer.ts +29 -3
- package/dist/signer/helpers.d.ts +0 -40
- package/dist/signer/helpers.d.ts.map +0 -1
- package/dist/signer/helpers.js +0 -90
- package/src/signer/helpers.ts +0 -122
package/dist/signer/helpers.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { ScriptLike, Transaction, TransactionLike } from "../ckb";
|
|
2
|
-
import { Client } from "../client";
|
|
3
|
-
import { Hex } from "../hex";
|
|
4
|
-
/**
|
|
5
|
-
* Computes the signing hash information for a given transaction and script.
|
|
6
|
-
*
|
|
7
|
-
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
8
|
-
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
9
|
-
* @param client - The client for complete extra infos in the transaction.
|
|
10
|
-
* @returns A promise that resolves to an object containing the signing message and the witness position,
|
|
11
|
-
* or undefined if no matching input is found.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const signHashInfo = await getSignHashInfo(transactionLike, scriptLike, client);
|
|
16
|
-
* if (signHashInfo) {
|
|
17
|
-
* console.log(signHashInfo.message); // Outputs the signing message
|
|
18
|
-
* console.log(signHashInfo.position); // Outputs the witness position
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare function getSignHashInfo(txLike: TransactionLike, scriptLike: ScriptLike, client: Client): Promise<{
|
|
23
|
-
message: Hex;
|
|
24
|
-
position: number;
|
|
25
|
-
} | undefined>;
|
|
26
|
-
/**
|
|
27
|
-
* Prepare dummy witness for sighash all method
|
|
28
|
-
*
|
|
29
|
-
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
30
|
-
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
31
|
-
* @param client - The client for complete extra infos in the transaction.
|
|
32
|
-
* @returns A promise that resolves to the prepared transaction
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* const tx = await prepareSighashAllWitness(transactionLike, scriptLike, client);
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare function prepareSighashAllWitness(txLike: TransactionLike, scriptLike: ScriptLike, lockLen: number, client: Client): Promise<Transaction>;
|
|
40
|
-
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,CA6BtB"}
|
package/dist/signer/helpers.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { Script, Transaction, WitnessArgs, } from "../ckb";
|
|
2
|
-
import { Hasher } from "../hasher";
|
|
3
|
-
import { hexFrom } from "../hex";
|
|
4
|
-
/**
|
|
5
|
-
* Computes the signing hash information for a given transaction and script.
|
|
6
|
-
*
|
|
7
|
-
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
8
|
-
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
9
|
-
* @param client - The client for complete extra infos in the transaction.
|
|
10
|
-
* @returns A promise that resolves to an object containing the signing message and the witness position,
|
|
11
|
-
* or undefined if no matching input is found.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const signHashInfo = await getSignHashInfo(transactionLike, scriptLike, client);
|
|
16
|
-
* if (signHashInfo) {
|
|
17
|
-
* console.log(signHashInfo.message); // Outputs the signing message
|
|
18
|
-
* console.log(signHashInfo.position); // Outputs the witness position
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export async function getSignHashInfo(txLike, scriptLike, client) {
|
|
23
|
-
const tx = Transaction.from(txLike);
|
|
24
|
-
const script = Script.from(scriptLike);
|
|
25
|
-
let position = -1;
|
|
26
|
-
const hasher = new Hasher();
|
|
27
|
-
hasher.update(tx.hash());
|
|
28
|
-
for (let i = 0; i < tx.witnesses.length; i += 1) {
|
|
29
|
-
if (tx.inputs[i]) {
|
|
30
|
-
const input = await tx.inputs[i].completeExtraInfos(client);
|
|
31
|
-
if (!input.cellOutput) {
|
|
32
|
-
throw Error("Unable to resolve inputs info");
|
|
33
|
-
}
|
|
34
|
-
if (!script.eq(input.cellOutput.lock)) {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (position === -1) {
|
|
38
|
-
position = i;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (position === -1) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
Transaction.hashWitnessToHasher(tx.witnesses[i], hasher);
|
|
45
|
-
}
|
|
46
|
-
if (position === -1) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
message: hasher.digest(),
|
|
51
|
-
position,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Prepare dummy witness for sighash all method
|
|
56
|
-
*
|
|
57
|
-
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
58
|
-
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
59
|
-
* @param client - The client for complete extra infos in the transaction.
|
|
60
|
-
* @returns A promise that resolves to the prepared transaction
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```typescript
|
|
64
|
-
* const tx = await prepareSighashAllWitness(transactionLike, scriptLike, client);
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export async function prepareSighashAllWitness(txLike, scriptLike, lockLen, client) {
|
|
68
|
-
const tx = Transaction.from(txLike);
|
|
69
|
-
const script = Script.from(scriptLike);
|
|
70
|
-
let position = -1;
|
|
71
|
-
for (let i = 0; i < tx.inputs.length; i += 1) {
|
|
72
|
-
const input = await tx.inputs[i].completeExtraInfos(client);
|
|
73
|
-
if (!input.cellOutput) {
|
|
74
|
-
throw Error("Unable to resolve inputs info");
|
|
75
|
-
}
|
|
76
|
-
if (script.eq(input.cellOutput.lock)) {
|
|
77
|
-
position = i;
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (position === -1) {
|
|
82
|
-
return tx;
|
|
83
|
-
}
|
|
84
|
-
const witness = tx.witnesses[position]
|
|
85
|
-
? WitnessArgs.fromBytes(tx.witnesses[position])
|
|
86
|
-
: WitnessArgs.from({});
|
|
87
|
-
witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
|
|
88
|
-
tx.witnesses[position] = hexFrom(witness.toBytes());
|
|
89
|
-
return tx;
|
|
90
|
-
}
|
package/src/signer/helpers.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Script,
|
|
3
|
-
ScriptLike,
|
|
4
|
-
Transaction,
|
|
5
|
-
TransactionLike,
|
|
6
|
-
WitnessArgs,
|
|
7
|
-
} from "../ckb";
|
|
8
|
-
import { Client } from "../client";
|
|
9
|
-
import { Hasher } from "../hasher";
|
|
10
|
-
import { Hex, hexFrom } from "../hex";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Computes the signing hash information for a given transaction and script.
|
|
14
|
-
*
|
|
15
|
-
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
16
|
-
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
17
|
-
* @param client - The client for complete extra infos in the transaction.
|
|
18
|
-
* @returns A promise that resolves to an object containing the signing message and the witness position,
|
|
19
|
-
* or undefined if no matching input is found.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* const signHashInfo = await getSignHashInfo(transactionLike, scriptLike, client);
|
|
24
|
-
* if (signHashInfo) {
|
|
25
|
-
* console.log(signHashInfo.message); // Outputs the signing message
|
|
26
|
-
* console.log(signHashInfo.position); // Outputs the witness position
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export async function getSignHashInfo(
|
|
31
|
-
txLike: TransactionLike,
|
|
32
|
-
scriptLike: ScriptLike,
|
|
33
|
-
client: Client,
|
|
34
|
-
): Promise<{ message: Hex; position: number } | undefined> {
|
|
35
|
-
const tx = Transaction.from(txLike);
|
|
36
|
-
const script = Script.from(scriptLike);
|
|
37
|
-
let position = -1;
|
|
38
|
-
const hasher = new Hasher();
|
|
39
|
-
hasher.update(tx.hash());
|
|
40
|
-
|
|
41
|
-
for (let i = 0; i < tx.witnesses.length; i += 1) {
|
|
42
|
-
if (tx.inputs[i]) {
|
|
43
|
-
const input = await tx.inputs[i].completeExtraInfos(client);
|
|
44
|
-
|
|
45
|
-
if (!input.cellOutput) {
|
|
46
|
-
throw Error("Unable to resolve inputs info");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!script.eq(input.cellOutput.lock)) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (position === -1) {
|
|
54
|
-
position = i;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (position === -1) {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
Transaction.hashWitnessToHasher(tx.witnesses[i], hasher);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (position === -1) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
message: hasher.digest(),
|
|
71
|
-
position,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Prepare dummy witness for sighash all method
|
|
77
|
-
*
|
|
78
|
-
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
79
|
-
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
80
|
-
* @param client - The client for complete extra infos in the transaction.
|
|
81
|
-
* @returns A promise that resolves to the prepared transaction
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```typescript
|
|
85
|
-
* const tx = await prepareSighashAllWitness(transactionLike, scriptLike, client);
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
export async function prepareSighashAllWitness(
|
|
89
|
-
txLike: TransactionLike,
|
|
90
|
-
scriptLike: ScriptLike,
|
|
91
|
-
lockLen: number,
|
|
92
|
-
client: Client,
|
|
93
|
-
): Promise<Transaction> {
|
|
94
|
-
const tx = Transaction.from(txLike);
|
|
95
|
-
const script = Script.from(scriptLike);
|
|
96
|
-
|
|
97
|
-
let position = -1;
|
|
98
|
-
|
|
99
|
-
for (let i = 0; i < tx.inputs.length; i += 1) {
|
|
100
|
-
const input = await tx.inputs[i].completeExtraInfos(client);
|
|
101
|
-
|
|
102
|
-
if (!input.cellOutput) {
|
|
103
|
-
throw Error("Unable to resolve inputs info");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (script.eq(input.cellOutput.lock)) {
|
|
107
|
-
position = i;
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (position === -1) {
|
|
112
|
-
return tx;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const witness = tx.witnesses[position]
|
|
116
|
-
? WitnessArgs.fromBytes(tx.witnesses[position])
|
|
117
|
-
: WitnessArgs.from({});
|
|
118
|
-
witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
|
|
119
|
-
tx.witnesses[position] = hexFrom(witness.toBytes());
|
|
120
|
-
|
|
121
|
-
return tx;
|
|
122
|
-
}
|