@ckb-ccc/core 0.0.4-alpha.4 → 0.0.4-alpha.6
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/client/advanced.d.ts +1 -0
- package/dist/client/advanced.d.ts.map +1 -1
- package/dist/client/advanced.js +1 -0
- package/dist/client/clientPublicMainnet.d.ts +1 -1
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.js +2 -2
- package/dist/client/clientPublicTestnet.d.ts +1 -1
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +2 -2
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/jsonRpc/index.js +2 -2
- package/dist/client/jsonRpc/transformers.d.ts +17 -17
- package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
- package/dist/client/jsonRpc/transformers.js +36 -36
- package/dist/signer/btc/signerBtc.d.ts +7 -0
- package/dist/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist/signer/btc/signerBtc.js +11 -1
- package/dist/signer/evm/signerEvm.d.ts +7 -0
- package/dist/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist/signer/evm/signerEvm.js +11 -1
- package/dist/signer/helpers.d.ts +17 -2
- package/dist/signer/helpers.d.ts.map +1 -1
- package/dist/signer/helpers.js +41 -2
- package/dist/signer/signer.d.ts +8 -0
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +12 -1
- package/package.json +2 -2
- package/src/client/clientPublicMainnet.ts +2 -2
- package/src/client/clientPublicTestnet.ts +2 -2
- package/src/client/jsonRpc/index.ts +2 -2
- package/src/client/jsonRpc/transformers.ts +38 -36
- package/src/signer/btc/signerBtc.ts +12 -1
- package/src/signer/evm/signerEvm.ts +12 -1
- package/src/signer/helpers.ts +59 -3
- package/src/signer/signer.ts +13 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/client/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/client/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oBAAoB,CAAC"}
|
package/dist/client/advanced.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Script } from "../ckb";
|
|
|
2
2
|
import { KnownScript } from "./client";
|
|
3
3
|
import { ClientJsonRpc } from "./jsonRpc";
|
|
4
4
|
export declare class ClientPublicMainnet extends ClientJsonRpc {
|
|
5
|
-
constructor(timeout?: number);
|
|
5
|
+
constructor(url?: string, timeout?: number);
|
|
6
6
|
getAddressPrefix(): Promise<string>;
|
|
7
7
|
getKnownScript(script: KnownScript): Promise<Pick<Script, "codeHash" | "hashType">>;
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPublicMainnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,qBAAa,mBAAoB,SAAQ,aAAa;gBACxC,OAAO,CAAC,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"clientPublicMainnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,qBAAa,mBAAoB,SAAQ,aAAa;gBACxC,GAAG,SAAgC,EAAE,OAAO,CAAC,EAAE,MAAM;IAI3D,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC,cAAc,CAClB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,CAAC;CAGlD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MAINNET_SCRIPTS } from "./clientPublicMainnet.advanced";
|
|
2
2
|
import { ClientJsonRpc } from "./jsonRpc";
|
|
3
3
|
export class ClientPublicMainnet extends ClientJsonRpc {
|
|
4
|
-
constructor(timeout) {
|
|
5
|
-
super(
|
|
4
|
+
constructor(url = "https://mainnet.ckbapp.dev/", timeout) {
|
|
5
|
+
super(url, timeout);
|
|
6
6
|
}
|
|
7
7
|
async getAddressPrefix() {
|
|
8
8
|
return "ckb";
|
|
@@ -2,7 +2,7 @@ import { Script } from "../ckb";
|
|
|
2
2
|
import { KnownScript } from "./client";
|
|
3
3
|
import { ClientJsonRpc } from "./jsonRpc";
|
|
4
4
|
export declare class ClientPublicTestnet extends ClientJsonRpc {
|
|
5
|
-
constructor(timeout?: number);
|
|
5
|
+
constructor(url?: string, timeout?: number);
|
|
6
6
|
getAddressPrefix(): Promise<string>;
|
|
7
7
|
getKnownScript(script: KnownScript): Promise<Pick<Script, "codeHash" | "hashType">>;
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPublicTestnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,qBAAa,mBAAoB,SAAQ,aAAa;gBACxC,OAAO,CAAC,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"clientPublicTestnet.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,qBAAa,mBAAoB,SAAQ,aAAa;gBACxC,GAAG,SAAgC,EAAE,OAAO,CAAC,EAAE,MAAM;IAI3D,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC,cAAc,CAClB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,CAAC;CAGlD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TESTNET_SCRIPTS } from "./clientPublicTestnet.advanced";
|
|
2
2
|
import { ClientJsonRpc } from "./jsonRpc";
|
|
3
3
|
export class ClientPublicTestnet extends ClientJsonRpc {
|
|
4
|
-
constructor(timeout) {
|
|
5
|
-
super(
|
|
4
|
+
constructor(url = "https://testnet.ckbapp.dev/", timeout) {
|
|
5
|
+
super(url, timeout);
|
|
6
6
|
}
|
|
7
7
|
async getAddressPrefix() {
|
|
8
8
|
return "ckt";
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC"}
|
package/dist/client/index.js
CHANGED
|
@@ -43,14 +43,14 @@ export class ClientJsonRpc extends Client {
|
|
|
43
43
|
* @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
|
|
44
44
|
* @returns Transaction hash.
|
|
45
45
|
*/
|
|
46
|
-
this.sendTransaction = this.buildSender("send_transaction", [JsonRpcTransformers.
|
|
46
|
+
this.sendTransaction = this.buildSender("send_transaction", [JsonRpcTransformers.transactionFrom], hexFrom);
|
|
47
47
|
/**
|
|
48
48
|
* Get a transaction from node.
|
|
49
49
|
*
|
|
50
50
|
* @param txHash - The hash of the transaction.
|
|
51
51
|
* @returns The transaction with status.
|
|
52
52
|
*/
|
|
53
|
-
this.getTransaction = this.buildSender("get_transaction", [hexFrom], JsonRpcTransformers.
|
|
53
|
+
this.getTransaction = this.buildSender("get_transaction", [hexFrom], JsonRpcTransformers.transactionResponseTo);
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* Returns the URL of the JSON-RPC server.
|
|
@@ -2,23 +2,23 @@ import { CellDep, CellDepLike, CellInput, CellInputLike, CellOutput, CellOutputL
|
|
|
2
2
|
import { ClientTransactionResponse, TransactionStatus } from "../clientTypes";
|
|
3
3
|
import { JsonRpcCellDep, JsonRpcCellInput, JsonRpcCellOutput, JsonRpcDepType, JsonRpcHashType, JsonRpcOutPoint, JsonRpcScript, JsonRpcTransaction } from "./types";
|
|
4
4
|
export declare class JsonRpcTransformers {
|
|
5
|
-
static
|
|
6
|
-
static
|
|
7
|
-
static
|
|
8
|
-
static
|
|
9
|
-
static
|
|
10
|
-
static
|
|
11
|
-
static
|
|
12
|
-
static
|
|
13
|
-
static
|
|
14
|
-
static
|
|
15
|
-
static
|
|
16
|
-
static
|
|
17
|
-
static
|
|
18
|
-
static
|
|
19
|
-
static
|
|
20
|
-
static
|
|
21
|
-
static
|
|
5
|
+
static hashTypeFrom(hashType: HashTypeLike): JsonRpcHashType;
|
|
6
|
+
static hashTypeTo(hashType: JsonRpcHashType): HashType;
|
|
7
|
+
static depTypeFrom(depType: DepTypeLike): JsonRpcDepType;
|
|
8
|
+
static depTypeTo(depType: JsonRpcDepType): DepType;
|
|
9
|
+
static scriptFrom(scriptLike: ScriptLike): JsonRpcScript;
|
|
10
|
+
static scriptTo(script: JsonRpcScript): Script;
|
|
11
|
+
static outPointFrom(outPointLike: OutPointLike): JsonRpcOutPoint;
|
|
12
|
+
static outPointTo(outPoint: JsonRpcOutPoint): OutPoint;
|
|
13
|
+
static cellInputFrom(cellInput: CellInputLike): JsonRpcCellInput;
|
|
14
|
+
static cellInputTo(cellInput: JsonRpcCellInput): CellInput;
|
|
15
|
+
static cellOutputFrom(cellOutput: CellOutputLike): JsonRpcCellOutput;
|
|
16
|
+
static cellOutputTo(cellOutput: JsonRpcCellOutput): CellOutput;
|
|
17
|
+
static cellDepFrom(cellDep: CellDepLike): JsonRpcCellDep;
|
|
18
|
+
static cellDepTo(cellDep: JsonRpcCellDep): CellDep;
|
|
19
|
+
static transactionFrom(txLike: TransactionLike): JsonRpcTransaction;
|
|
20
|
+
static transactionTo(tx: JsonRpcTransaction): Transaction;
|
|
21
|
+
static transactionResponseTo({ tx_status: { status }, transaction, }: {
|
|
22
22
|
tx_status: {
|
|
23
23
|
status: TransactionStatus;
|
|
24
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/transformers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,SAAS,EACT,aAAa,EACb,UAAU,EACV,cAAc,EACd,OAAO,EACP,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,UAAU,EACV,WAAW,EACX,eAAe,EAGhB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,eAAe,EACf,aAAa,EACb,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,qBAAa,mBAAmB;IAC9B,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/transformers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,SAAS,EACT,aAAa,EACb,UAAU,EACV,cAAc,EACd,OAAO,EACP,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,UAAU,EACV,WAAW,EACX,eAAe,EAGhB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,eAAe,EACf,aAAa,EACb,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,qBAAa,mBAAmB;IAC9B,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,YAAY,GAAG,eAAe;IAG5D,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,eAAe,GAAG,QAAQ;IAGtD,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc;IAQxD,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO;IAQlD,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa;IAQxD,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM;IAO9C,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,eAAe;IAOhE,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,eAAe,GAAG,QAAQ;IAMtD,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,aAAa,GAAG,gBAAgB;IAQhE,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,gBAAgB,GAAG,SAAS;IAM1D,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,cAAc,GAAG,iBAAiB;IAOpE,MAAM,CAAC,YAAY,CAAC,UAAU,EAAE,iBAAiB,GAAG,UAAU;IAO9D,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc;IAMxD,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO;IAMlD,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,kBAAkB;IAYnE,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,kBAAkB,GAAG,WAAW;IAWzD,MAAM,CAAC,qBAAqB,CAAC,EAC3B,SAAS,EAAE,EAAE,MAAM,EAAE,EACrB,WAAW,GACZ,EAAE;QACD,SAAS,EAAE;YAAE,MAAM,EAAE,iBAAiB,CAAA;SAAE,CAAC;QACzC,WAAW,EAAE,kBAAkB,CAAC;KACjC,GAAG,yBAAyB;CAM9B"}
|
|
@@ -2,13 +2,13 @@ import { CellDep, CellInput, CellOutput, OutPoint, Script, Transaction, depTypeF
|
|
|
2
2
|
import { numToHex } from "../../num";
|
|
3
3
|
import { apply } from "../../utils";
|
|
4
4
|
export class JsonRpcTransformers {
|
|
5
|
-
static
|
|
5
|
+
static hashTypeFrom(hashType) {
|
|
6
6
|
return hashTypeFrom(hashType);
|
|
7
7
|
}
|
|
8
|
-
static
|
|
8
|
+
static hashTypeTo(hashType) {
|
|
9
9
|
return hashType;
|
|
10
10
|
}
|
|
11
|
-
static
|
|
11
|
+
static depTypeFrom(depType) {
|
|
12
12
|
switch (depTypeFrom(depType)) {
|
|
13
13
|
case "code":
|
|
14
14
|
return "code";
|
|
@@ -16,7 +16,7 @@ export class JsonRpcTransformers {
|
|
|
16
16
|
return "dep_group";
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
static
|
|
19
|
+
static depTypeTo(depType) {
|
|
20
20
|
switch (depType) {
|
|
21
21
|
case "code":
|
|
22
22
|
return "code";
|
|
@@ -24,98 +24,98 @@ export class JsonRpcTransformers {
|
|
|
24
24
|
return "depGroup";
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
static
|
|
27
|
+
static scriptFrom(scriptLike) {
|
|
28
28
|
const script = Script.from(scriptLike);
|
|
29
29
|
return {
|
|
30
30
|
code_hash: script.codeHash,
|
|
31
|
-
hash_type: JsonRpcTransformers.
|
|
31
|
+
hash_type: JsonRpcTransformers.hashTypeFrom(script.hashType),
|
|
32
32
|
args: script.args,
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
static
|
|
35
|
+
static scriptTo(script) {
|
|
36
36
|
return Script.from({
|
|
37
37
|
codeHash: script.code_hash,
|
|
38
|
-
hashType: JsonRpcTransformers.
|
|
38
|
+
hashType: JsonRpcTransformers.hashTypeTo(script.hash_type),
|
|
39
39
|
args: script.args,
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
static
|
|
42
|
+
static outPointFrom(outPointLike) {
|
|
43
43
|
const outPoint = OutPoint.from(outPointLike);
|
|
44
44
|
return {
|
|
45
45
|
index: numToHex(outPoint.index),
|
|
46
46
|
tx_hash: outPoint.txHash,
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
static
|
|
49
|
+
static outPointTo(outPoint) {
|
|
50
50
|
return OutPoint.from({
|
|
51
51
|
index: outPoint.index,
|
|
52
52
|
txHash: outPoint.tx_hash,
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
static
|
|
55
|
+
static cellInputFrom(cellInput) {
|
|
56
56
|
return {
|
|
57
|
-
previous_output: JsonRpcTransformers.
|
|
57
|
+
previous_output: JsonRpcTransformers.outPointFrom(cellInput.previousOutput),
|
|
58
58
|
since: numToHex(cellInput.since),
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
static
|
|
61
|
+
static cellInputTo(cellInput) {
|
|
62
62
|
return CellInput.from({
|
|
63
|
-
previousOutput:
|
|
63
|
+
previousOutput: JsonRpcTransformers.outPointTo(cellInput.previous_output),
|
|
64
64
|
since: cellInput.since,
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
static
|
|
67
|
+
static cellOutputFrom(cellOutput) {
|
|
68
68
|
return {
|
|
69
69
|
capacity: numToHex(cellOutput.capacity),
|
|
70
|
-
lock: JsonRpcTransformers.
|
|
71
|
-
type: apply(JsonRpcTransformers.
|
|
70
|
+
lock: JsonRpcTransformers.scriptFrom(cellOutput.lock),
|
|
71
|
+
type: apply(JsonRpcTransformers.scriptFrom, cellOutput.type),
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
-
static
|
|
74
|
+
static cellOutputTo(cellOutput) {
|
|
75
75
|
return CellOutput.from({
|
|
76
76
|
capacity: cellOutput.capacity,
|
|
77
|
-
lock: JsonRpcTransformers.
|
|
78
|
-
type: apply(JsonRpcTransformers.
|
|
77
|
+
lock: JsonRpcTransformers.scriptTo(cellOutput.lock),
|
|
78
|
+
type: apply(JsonRpcTransformers.scriptTo, cellOutput.type),
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
-
static
|
|
81
|
+
static cellDepFrom(cellDep) {
|
|
82
82
|
return {
|
|
83
|
-
out_point: JsonRpcTransformers.
|
|
84
|
-
dep_type: JsonRpcTransformers.
|
|
83
|
+
out_point: JsonRpcTransformers.outPointFrom(cellDep.outPoint),
|
|
84
|
+
dep_type: JsonRpcTransformers.depTypeFrom(cellDep.depType),
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
static
|
|
87
|
+
static cellDepTo(cellDep) {
|
|
88
88
|
return CellDep.from({
|
|
89
|
-
outPoint: JsonRpcTransformers.
|
|
90
|
-
depType: JsonRpcTransformers.
|
|
89
|
+
outPoint: JsonRpcTransformers.outPointTo(cellDep.out_point),
|
|
90
|
+
depType: JsonRpcTransformers.depTypeTo(cellDep.dep_type),
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
|
-
static
|
|
93
|
+
static transactionFrom(txLike) {
|
|
94
94
|
const tx = Transaction.from(txLike);
|
|
95
95
|
return {
|
|
96
96
|
version: numToHex(tx.version),
|
|
97
|
-
cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.
|
|
97
|
+
cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.cellDepFrom(c)),
|
|
98
98
|
header_deps: tx.headerDeps,
|
|
99
|
-
inputs: tx.inputs.map((i) => JsonRpcTransformers.
|
|
100
|
-
outputs: tx.outputs.map((o) => JsonRpcTransformers.
|
|
99
|
+
inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputFrom(i)),
|
|
100
|
+
outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputFrom(o)),
|
|
101
101
|
outputs_data: tx.outputsData,
|
|
102
102
|
witnesses: tx.witnesses,
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
static
|
|
105
|
+
static transactionTo(tx) {
|
|
106
106
|
return Transaction.from({
|
|
107
107
|
version: tx.version,
|
|
108
|
-
cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.
|
|
108
|
+
cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.cellDepTo(c)),
|
|
109
109
|
headerDeps: tx.header_deps,
|
|
110
|
-
inputs: tx.inputs.map((i) => JsonRpcTransformers.
|
|
111
|
-
outputs: tx.outputs.map((o) => JsonRpcTransformers.
|
|
110
|
+
inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputTo(i)),
|
|
111
|
+
outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputTo(o)),
|
|
112
112
|
outputsData: tx.outputs_data,
|
|
113
113
|
witnesses: tx.witnesses,
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
|
-
static
|
|
116
|
+
static transactionResponseTo({ tx_status: { status }, transaction, }) {
|
|
117
117
|
return {
|
|
118
|
-
transaction: JsonRpcTransformers.
|
|
118
|
+
transaction: JsonRpcTransformers.transactionTo(transaction),
|
|
119
119
|
status,
|
|
120
120
|
};
|
|
121
121
|
}
|
|
@@ -32,6 +32,13 @@ export declare abstract class SignerBtc extends Signer {
|
|
|
32
32
|
* @returns A promise that resolves to an array of Address objects.
|
|
33
33
|
*/
|
|
34
34
|
getAddressObjs(): Promise<Address[]>;
|
|
35
|
+
/**
|
|
36
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
37
|
+
*
|
|
38
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
39
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
40
|
+
*/
|
|
41
|
+
prepareTransaction(txLike: TransactionLike): Promise<Transaction>;
|
|
35
42
|
/**
|
|
36
43
|
* Signs a transaction without modifying it.
|
|
37
44
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signerBtc.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;;GAIG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAE5C;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAa1C;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAgCzE"}
|
|
1
|
+
{"version":3,"file":"signerBtc.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;;GAIG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAE5C;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAa1C;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAKvE;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAgCzE"}
|
|
@@ -6,7 +6,7 @@ import { Transaction, WitnessArgs } from "../../ckb";
|
|
|
6
6
|
import { KnownScript } from "../../client";
|
|
7
7
|
import { hexFrom } from "../../hex";
|
|
8
8
|
import { numToBytes } from "../../num";
|
|
9
|
-
import { getSignHashInfo } from "../helpers";
|
|
9
|
+
import { getSignHashInfo, prepareSighashAllWitness } from "../helpers";
|
|
10
10
|
import { Signer } from "../signer";
|
|
11
11
|
/**
|
|
12
12
|
* An abstract class extending the Signer class for Bitcoin-like signing operations.
|
|
@@ -34,6 +34,16 @@ export class SignerBtc extends Signer {
|
|
|
34
34
|
await Address.fromKnownScript(KnownScript.OmniLock, hexFrom([0x04, ...hash, 0x00]), this.client),
|
|
35
35
|
];
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
39
|
+
*
|
|
40
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
41
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
42
|
+
*/
|
|
43
|
+
async prepareTransaction(txLike) {
|
|
44
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
45
|
+
return prepareSighashAllWitness(txLike, script, 85, this.client);
|
|
46
|
+
}
|
|
37
47
|
/**
|
|
38
48
|
* Signs a transaction without modifying it.
|
|
39
49
|
*
|
|
@@ -24,6 +24,13 @@ export declare abstract class SignerEvm extends Signer {
|
|
|
24
24
|
* @returns A promise that resolves to an array of Address objects.
|
|
25
25
|
*/
|
|
26
26
|
getAddressObjs(): Promise<Address[]>;
|
|
27
|
+
/**
|
|
28
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
29
|
+
*
|
|
30
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
31
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
32
|
+
*/
|
|
33
|
+
prepareTransaction(txLike: TransactionLike): Promise<Transaction>;
|
|
27
34
|
/**
|
|
28
35
|
* Signs a transaction without modifying it.
|
|
29
36
|
*
|
|
@@ -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;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAKtE,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;IAW1C;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAgCzE"}
|
|
1
|
+
{"version":3,"file":"signerEvm.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAKtE,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;IAW1C;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAKvE;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAgCzE"}
|
|
@@ -4,7 +4,7 @@ import { Transaction, WitnessArgs } from "../../ckb";
|
|
|
4
4
|
import { KnownScript } from "../../client";
|
|
5
5
|
import { hexFrom } from "../../hex";
|
|
6
6
|
import { numToBytes } from "../../num";
|
|
7
|
-
import { getSignHashInfo } from "../helpers";
|
|
7
|
+
import { getSignHashInfo, prepareSighashAllWitness } from "../helpers";
|
|
8
8
|
import { Signer } from "../signer";
|
|
9
9
|
/**
|
|
10
10
|
* An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
|
|
@@ -30,6 +30,16 @@ export class SignerEvm extends Signer {
|
|
|
30
30
|
await Address.fromKnownScript(KnownScript.OmniLock, hexFrom([0x12, ...bytesFrom(account), 0x00]), this.client),
|
|
31
31
|
];
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
35
|
+
*
|
|
36
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
37
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
38
|
+
*/
|
|
39
|
+
async prepareTransaction(txLike) {
|
|
40
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
41
|
+
return prepareSighashAllWitness(txLike, script, 85, this.client);
|
|
42
|
+
}
|
|
33
43
|
/**
|
|
34
44
|
* Signs a transaction without modifying it.
|
|
35
45
|
*
|
package/dist/signer/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ScriptLike, TransactionLike } from "../ckb";
|
|
1
|
+
import { ScriptLike, Transaction, TransactionLike } from "../ckb";
|
|
2
2
|
import { Client } from "../client";
|
|
3
3
|
import { Hex } from "../hex";
|
|
4
4
|
/**
|
|
@@ -6,12 +6,13 @@ import { Hex } from "../hex";
|
|
|
6
6
|
*
|
|
7
7
|
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
8
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.
|
|
9
10
|
* @returns A promise that resolves to an object containing the signing message and the witness position,
|
|
10
11
|
* or undefined if no matching input is found.
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
14
|
* ```typescript
|
|
14
|
-
* const signHashInfo = await getSignHashInfo(transactionLike, scriptLike);
|
|
15
|
+
* const signHashInfo = await getSignHashInfo(transactionLike, scriptLike, client);
|
|
15
16
|
* if (signHashInfo) {
|
|
16
17
|
* console.log(signHashInfo.message); // Outputs the signing message
|
|
17
18
|
* console.log(signHashInfo.position); // Outputs the witness position
|
|
@@ -22,4 +23,18 @@ export declare function getSignHashInfo(txLike: TransactionLike, scriptLike: Scr
|
|
|
22
23
|
message: Hex;
|
|
23
24
|
position: number;
|
|
24
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>;
|
|
25
40
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/signer/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { Script, Transaction } from "../ckb";
|
|
1
|
+
import { Script, Transaction, WitnessArgs, } from "../ckb";
|
|
2
2
|
import { Hasher } from "../hasher";
|
|
3
|
+
import { hexFrom } from "../hex";
|
|
3
4
|
/**
|
|
4
5
|
* Computes the signing hash information for a given transaction and script.
|
|
5
6
|
*
|
|
6
7
|
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
7
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.
|
|
8
10
|
* @returns A promise that resolves to an object containing the signing message and the witness position,
|
|
9
11
|
* or undefined if no matching input is found.
|
|
10
12
|
*
|
|
11
13
|
* @example
|
|
12
14
|
* ```typescript
|
|
13
|
-
* const signHashInfo = await getSignHashInfo(transactionLike, scriptLike);
|
|
15
|
+
* const signHashInfo = await getSignHashInfo(transactionLike, scriptLike, client);
|
|
14
16
|
* if (signHashInfo) {
|
|
15
17
|
* console.log(signHashInfo.message); // Outputs the signing message
|
|
16
18
|
* console.log(signHashInfo.position); // Outputs the witness position
|
|
@@ -49,3 +51,40 @@ export async function getSignHashInfo(txLike, scriptLike, client) {
|
|
|
49
51
|
position,
|
|
50
52
|
};
|
|
51
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/dist/signer/signer.d.ts
CHANGED
|
@@ -70,6 +70,14 @@ export declare abstract class Signer {
|
|
|
70
70
|
* @returns A promise that resolves to the signed Transaction object.
|
|
71
71
|
*/
|
|
72
72
|
signTransaction(tx: TransactionLike): Promise<Transaction>;
|
|
73
|
+
/**
|
|
74
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
75
|
+
*
|
|
76
|
+
* @param _ - The transaction to prepare, represented as a TransactionLike object.
|
|
77
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
78
|
+
* @throws Will throw an error if not implemented.
|
|
79
|
+
*/
|
|
80
|
+
prepareTransaction(_: TransactionLike): Promise<Transaction>;
|
|
73
81
|
/**
|
|
74
82
|
* Signs a transaction without sending it. This method is not implemented and should be overridden by subclasses.
|
|
75
83
|
*
|
|
@@ -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;aACE,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;IAE1C;;;;OAIG;IACH,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAEjC;;;;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;
|
|
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;aACE,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;IAE1C;;;;OAIG;IACH,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAEjC;;;;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;IACb,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB,CAAC"}
|
package/dist/signer/signer.js
CHANGED
|
@@ -58,7 +58,18 @@ export class Signer {
|
|
|
58
58
|
* @returns A promise that resolves to the signed Transaction object.
|
|
59
59
|
*/
|
|
60
60
|
async signTransaction(tx) {
|
|
61
|
-
|
|
61
|
+
const preparedTx = await this.prepareTransaction(tx);
|
|
62
|
+
return this.signOnlyTransaction(preparedTx);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
66
|
+
*
|
|
67
|
+
* @param _ - The transaction to prepare, represented as a TransactionLike object.
|
|
68
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
69
|
+
* @throws Will throw an error if not implemented.
|
|
70
|
+
*/
|
|
71
|
+
prepareTransaction(_) {
|
|
72
|
+
throw Error("Signer.prepareTransaction not implemented");
|
|
62
73
|
}
|
|
63
74
|
/**
|
|
64
75
|
* Signs a transaction without sending it. This method is not implemented and should be overridden by subclasses.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/core",
|
|
3
|
-
"version": "0.0.4-alpha.
|
|
3
|
+
"version": "0.0.4-alpha.6",
|
|
4
4
|
"description": "Common Chains Connector Core",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"buffer": "^6.0.3",
|
|
48
48
|
"cross-fetch": "^4.0.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "fa3a826161865b4f04db0ca2cb764c6badd3ceb9"
|
|
51
51
|
}
|
|
@@ -4,8 +4,8 @@ import { MAINNET_SCRIPTS } from "./clientPublicMainnet.advanced";
|
|
|
4
4
|
import { ClientJsonRpc } from "./jsonRpc";
|
|
5
5
|
|
|
6
6
|
export class ClientPublicMainnet extends ClientJsonRpc {
|
|
7
|
-
constructor(timeout?: number) {
|
|
8
|
-
super(
|
|
7
|
+
constructor(url = "https://mainnet.ckbapp.dev/", timeout?: number) {
|
|
8
|
+
super(url, timeout);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
async getAddressPrefix(): Promise<string> {
|
|
@@ -4,8 +4,8 @@ import { TESTNET_SCRIPTS } from "./clientPublicTestnet.advanced";
|
|
|
4
4
|
import { ClientJsonRpc } from "./jsonRpc";
|
|
5
5
|
|
|
6
6
|
export class ClientPublicTestnet extends ClientJsonRpc {
|
|
7
|
-
constructor(timeout?: number) {
|
|
8
|
-
super(
|
|
7
|
+
constructor(url = "https://testnet.ckbapp.dev/", timeout?: number) {
|
|
8
|
+
super(url, timeout);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
async getAddressPrefix(): Promise<string> {
|
|
@@ -69,7 +69,7 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
69
69
|
|
|
70
70
|
sendTransaction = this.buildSender(
|
|
71
71
|
"send_transaction",
|
|
72
|
-
[JsonRpcTransformers.
|
|
72
|
+
[JsonRpcTransformers.transactionFrom],
|
|
73
73
|
hexFrom,
|
|
74
74
|
) as (
|
|
75
75
|
transaction: TransactionLike,
|
|
@@ -86,7 +86,7 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
86
86
|
getTransaction = this.buildSender(
|
|
87
87
|
"get_transaction",
|
|
88
88
|
[hexFrom],
|
|
89
|
-
JsonRpcTransformers.
|
|
89
|
+
JsonRpcTransformers.transactionResponseTo,
|
|
90
90
|
) as (txHash: HexLike) => Promise<ClientTransactionResponse>;
|
|
91
91
|
|
|
92
92
|
/**
|
|
@@ -33,13 +33,13 @@ import {
|
|
|
33
33
|
} from "./types";
|
|
34
34
|
|
|
35
35
|
export class JsonRpcTransformers {
|
|
36
|
-
static
|
|
36
|
+
static hashTypeFrom(hashType: HashTypeLike): JsonRpcHashType {
|
|
37
37
|
return hashTypeFrom(hashType);
|
|
38
38
|
}
|
|
39
|
-
static
|
|
39
|
+
static hashTypeTo(hashType: JsonRpcHashType): HashType {
|
|
40
40
|
return hashType;
|
|
41
41
|
}
|
|
42
|
-
static
|
|
42
|
+
static depTypeFrom(depType: DepTypeLike): JsonRpcDepType {
|
|
43
43
|
switch (depTypeFrom(depType)) {
|
|
44
44
|
case "code":
|
|
45
45
|
return "code";
|
|
@@ -47,7 +47,7 @@ export class JsonRpcTransformers {
|
|
|
47
47
|
return "dep_group";
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
static
|
|
50
|
+
static depTypeTo(depType: JsonRpcDepType): DepType {
|
|
51
51
|
switch (depType) {
|
|
52
52
|
case "code":
|
|
53
53
|
return "code";
|
|
@@ -55,96 +55,98 @@ export class JsonRpcTransformers {
|
|
|
55
55
|
return "depGroup";
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
static
|
|
58
|
+
static scriptFrom(scriptLike: ScriptLike): JsonRpcScript {
|
|
59
59
|
const script = Script.from(scriptLike);
|
|
60
60
|
return {
|
|
61
61
|
code_hash: script.codeHash,
|
|
62
|
-
hash_type: JsonRpcTransformers.
|
|
62
|
+
hash_type: JsonRpcTransformers.hashTypeFrom(script.hashType),
|
|
63
63
|
args: script.args,
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
-
static
|
|
66
|
+
static scriptTo(script: JsonRpcScript): Script {
|
|
67
67
|
return Script.from({
|
|
68
68
|
codeHash: script.code_hash,
|
|
69
|
-
hashType: JsonRpcTransformers.
|
|
69
|
+
hashType: JsonRpcTransformers.hashTypeTo(script.hash_type),
|
|
70
70
|
args: script.args,
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
static
|
|
73
|
+
static outPointFrom(outPointLike: OutPointLike): JsonRpcOutPoint {
|
|
74
74
|
const outPoint = OutPoint.from(outPointLike);
|
|
75
75
|
return {
|
|
76
76
|
index: numToHex(outPoint.index),
|
|
77
77
|
tx_hash: outPoint.txHash,
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
static
|
|
80
|
+
static outPointTo(outPoint: JsonRpcOutPoint): OutPoint {
|
|
81
81
|
return OutPoint.from({
|
|
82
82
|
index: outPoint.index,
|
|
83
83
|
txHash: outPoint.tx_hash,
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
-
static
|
|
86
|
+
static cellInputFrom(cellInput: CellInputLike): JsonRpcCellInput {
|
|
87
87
|
return {
|
|
88
|
-
previous_output: JsonRpcTransformers.
|
|
88
|
+
previous_output: JsonRpcTransformers.outPointFrom(
|
|
89
|
+
cellInput.previousOutput,
|
|
90
|
+
),
|
|
89
91
|
since: numToHex(cellInput.since),
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
|
-
static
|
|
94
|
+
static cellInputTo(cellInput: JsonRpcCellInput): CellInput {
|
|
93
95
|
return CellInput.from({
|
|
94
|
-
previousOutput:
|
|
96
|
+
previousOutput: JsonRpcTransformers.outPointTo(cellInput.previous_output),
|
|
95
97
|
since: cellInput.since,
|
|
96
98
|
});
|
|
97
99
|
}
|
|
98
|
-
static
|
|
100
|
+
static cellOutputFrom(cellOutput: CellOutputLike): JsonRpcCellOutput {
|
|
99
101
|
return {
|
|
100
102
|
capacity: numToHex(cellOutput.capacity),
|
|
101
|
-
lock: JsonRpcTransformers.
|
|
102
|
-
type: apply(JsonRpcTransformers.
|
|
103
|
+
lock: JsonRpcTransformers.scriptFrom(cellOutput.lock),
|
|
104
|
+
type: apply(JsonRpcTransformers.scriptFrom, cellOutput.type),
|
|
103
105
|
};
|
|
104
106
|
}
|
|
105
|
-
static
|
|
107
|
+
static cellOutputTo(cellOutput: JsonRpcCellOutput): CellOutput {
|
|
106
108
|
return CellOutput.from({
|
|
107
109
|
capacity: cellOutput.capacity,
|
|
108
|
-
lock: JsonRpcTransformers.
|
|
109
|
-
type: apply(JsonRpcTransformers.
|
|
110
|
+
lock: JsonRpcTransformers.scriptTo(cellOutput.lock),
|
|
111
|
+
type: apply(JsonRpcTransformers.scriptTo, cellOutput.type),
|
|
110
112
|
});
|
|
111
113
|
}
|
|
112
|
-
static
|
|
114
|
+
static cellDepFrom(cellDep: CellDepLike): JsonRpcCellDep {
|
|
113
115
|
return {
|
|
114
|
-
out_point: JsonRpcTransformers.
|
|
115
|
-
dep_type: JsonRpcTransformers.
|
|
116
|
+
out_point: JsonRpcTransformers.outPointFrom(cellDep.outPoint),
|
|
117
|
+
dep_type: JsonRpcTransformers.depTypeFrom(cellDep.depType),
|
|
116
118
|
};
|
|
117
119
|
}
|
|
118
|
-
static
|
|
120
|
+
static cellDepTo(cellDep: JsonRpcCellDep): CellDep {
|
|
119
121
|
return CellDep.from({
|
|
120
|
-
outPoint: JsonRpcTransformers.
|
|
121
|
-
depType: JsonRpcTransformers.
|
|
122
|
+
outPoint: JsonRpcTransformers.outPointTo(cellDep.out_point),
|
|
123
|
+
depType: JsonRpcTransformers.depTypeTo(cellDep.dep_type),
|
|
122
124
|
});
|
|
123
125
|
}
|
|
124
|
-
static
|
|
126
|
+
static transactionFrom(txLike: TransactionLike): JsonRpcTransaction {
|
|
125
127
|
const tx = Transaction.from(txLike);
|
|
126
128
|
return {
|
|
127
129
|
version: numToHex(tx.version),
|
|
128
|
-
cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.
|
|
130
|
+
cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.cellDepFrom(c)),
|
|
129
131
|
header_deps: tx.headerDeps,
|
|
130
|
-
inputs: tx.inputs.map((i) => JsonRpcTransformers.
|
|
131
|
-
outputs: tx.outputs.map((o) => JsonRpcTransformers.
|
|
132
|
+
inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputFrom(i)),
|
|
133
|
+
outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputFrom(o)),
|
|
132
134
|
outputs_data: tx.outputsData,
|
|
133
135
|
witnesses: tx.witnesses,
|
|
134
136
|
};
|
|
135
137
|
}
|
|
136
|
-
static
|
|
138
|
+
static transactionTo(tx: JsonRpcTransaction): Transaction {
|
|
137
139
|
return Transaction.from({
|
|
138
140
|
version: tx.version,
|
|
139
|
-
cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.
|
|
141
|
+
cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.cellDepTo(c)),
|
|
140
142
|
headerDeps: tx.header_deps,
|
|
141
|
-
inputs: tx.inputs.map((i) => JsonRpcTransformers.
|
|
142
|
-
outputs: tx.outputs.map((o) => JsonRpcTransformers.
|
|
143
|
+
inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputTo(i)),
|
|
144
|
+
outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputTo(o)),
|
|
143
145
|
outputsData: tx.outputs_data,
|
|
144
146
|
witnesses: tx.witnesses,
|
|
145
147
|
});
|
|
146
148
|
}
|
|
147
|
-
static
|
|
149
|
+
static transactionResponseTo({
|
|
148
150
|
tx_status: { status },
|
|
149
151
|
transaction,
|
|
150
152
|
}: {
|
|
@@ -152,7 +154,7 @@ export class JsonRpcTransformers {
|
|
|
152
154
|
transaction: JsonRpcTransaction;
|
|
153
155
|
}): ClientTransactionResponse {
|
|
154
156
|
return {
|
|
155
|
-
transaction: JsonRpcTransformers.
|
|
157
|
+
transaction: JsonRpcTransformers.transactionTo(transaction),
|
|
156
158
|
status,
|
|
157
159
|
};
|
|
158
160
|
}
|
|
@@ -6,7 +6,7 @@ import { Transaction, TransactionLike, WitnessArgs } from "../../ckb";
|
|
|
6
6
|
import { KnownScript } from "../../client";
|
|
7
7
|
import { HexLike, hexFrom } from "../../hex";
|
|
8
8
|
import { numToBytes } from "../../num";
|
|
9
|
-
import { getSignHashInfo } from "../helpers";
|
|
9
|
+
import { getSignHashInfo, prepareSighashAllWitness } from "../helpers";
|
|
10
10
|
import { Signer } from "../signer";
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -56,6 +56,17 @@ export abstract class SignerBtc extends Signer {
|
|
|
56
56
|
];
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/**
|
|
60
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
61
|
+
*
|
|
62
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
63
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
64
|
+
*/
|
|
65
|
+
async prepareTransaction(txLike: TransactionLike): Promise<Transaction> {
|
|
66
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
67
|
+
return prepareSighashAllWitness(txLike, script, 85, this.client);
|
|
68
|
+
}
|
|
69
|
+
|
|
59
70
|
/**
|
|
60
71
|
* Signs a transaction without modifying it.
|
|
61
72
|
*
|
|
@@ -4,7 +4,7 @@ import { Transaction, TransactionLike, WitnessArgs } from "../../ckb";
|
|
|
4
4
|
import { KnownScript } from "../../client";
|
|
5
5
|
import { hexFrom } from "../../hex";
|
|
6
6
|
import { numToBytes } from "../../num";
|
|
7
|
-
import { getSignHashInfo } from "../helpers";
|
|
7
|
+
import { getSignHashInfo, prepareSighashAllWitness } from "../helpers";
|
|
8
8
|
import { Signer } from "../signer";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -44,6 +44,17 @@ export abstract class SignerEvm extends Signer {
|
|
|
44
44
|
];
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
49
|
+
*
|
|
50
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
51
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
52
|
+
*/
|
|
53
|
+
async prepareTransaction(txLike: TransactionLike): Promise<Transaction> {
|
|
54
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
55
|
+
return prepareSighashAllWitness(txLike, script, 85, this.client);
|
|
56
|
+
}
|
|
57
|
+
|
|
47
58
|
/**
|
|
48
59
|
* Signs a transaction without modifying it.
|
|
49
60
|
*
|
package/src/signer/helpers.ts
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Script,
|
|
3
|
+
ScriptLike,
|
|
4
|
+
Transaction,
|
|
5
|
+
TransactionLike,
|
|
6
|
+
WitnessArgs,
|
|
7
|
+
} from "../ckb";
|
|
2
8
|
import { Client } from "../client";
|
|
3
9
|
import { Hasher } from "../hasher";
|
|
4
|
-
import { Hex } from "../hex";
|
|
10
|
+
import { Hex, hexFrom } from "../hex";
|
|
5
11
|
|
|
6
12
|
/**
|
|
7
13
|
* Computes the signing hash information for a given transaction and script.
|
|
8
14
|
*
|
|
9
15
|
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
10
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.
|
|
11
18
|
* @returns A promise that resolves to an object containing the signing message and the witness position,
|
|
12
19
|
* or undefined if no matching input is found.
|
|
13
20
|
*
|
|
14
21
|
* @example
|
|
15
22
|
* ```typescript
|
|
16
|
-
* const signHashInfo = await getSignHashInfo(transactionLike, scriptLike);
|
|
23
|
+
* const signHashInfo = await getSignHashInfo(transactionLike, scriptLike, client);
|
|
17
24
|
* if (signHashInfo) {
|
|
18
25
|
* console.log(signHashInfo.message); // Outputs the signing message
|
|
19
26
|
* console.log(signHashInfo.position); // Outputs the witness position
|
|
@@ -64,3 +71,52 @@ export async function getSignHashInfo(
|
|
|
64
71
|
position,
|
|
65
72
|
};
|
|
66
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
|
+
}
|
package/src/signer/signer.ts
CHANGED
|
@@ -91,7 +91,19 @@ export abstract class Signer {
|
|
|
91
91
|
* @returns A promise that resolves to the signed Transaction object.
|
|
92
92
|
*/
|
|
93
93
|
async signTransaction(tx: TransactionLike): Promise<Transaction> {
|
|
94
|
-
|
|
94
|
+
const preparedTx = await this.prepareTransaction(tx);
|
|
95
|
+
return this.signOnlyTransaction(preparedTx);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
100
|
+
*
|
|
101
|
+
* @param _ - The transaction to prepare, represented as a TransactionLike object.
|
|
102
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
103
|
+
* @throws Will throw an error if not implemented.
|
|
104
|
+
*/
|
|
105
|
+
prepareTransaction(_: TransactionLike): Promise<Transaction> {
|
|
106
|
+
throw Error("Signer.prepareTransaction not implemented");
|
|
95
107
|
}
|
|
96
108
|
|
|
97
109
|
/**
|