@ckb-ccc/core 0.0.13-alpha.8 → 0.0.14-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/CHANGELOG.md +57 -0
- package/dist/client/client.d.ts +3 -1
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +9 -2
- package/dist/client/clientTypes.d.ts +12 -4
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/clientTypes.js +13 -1
- package/dist/client/jsonRpc/index.d.ts +10 -1
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +48 -14
- package/dist/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -1
- package/dist/signer/ckb/signerCkbPrivateKey.js +9 -8
- package/dist/signer/ckb/signerCkbPublicKey.d.ts +8 -2
- package/dist/signer/ckb/signerCkbPublicKey.d.ts.map +1 -1
- package/dist/signer/ckb/signerCkbPublicKey.js +65 -7
- package/dist.commonjs/client/client.d.ts +3 -1
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +9 -2
- package/dist.commonjs/client/clientTypes.d.ts +12 -4
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
- package/dist.commonjs/client/clientTypes.js +16 -2
- package/dist.commonjs/client/jsonRpc/index.d.ts +10 -1
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +46 -12
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +9 -8
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts +8 -2
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +64 -6
- package/package.json +1 -1
- package/src/client/client.ts +23 -2
- package/src/client/clientTypes.ts +27 -5
- package/src/client/jsonRpc/index.ts +97 -30
- package/src/signer/ckb/signerCkbPrivateKey.ts +13 -9
- package/src/signer/ckb/signerCkbPublicKey.ts +97 -12
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Address } from "../../address/index.js";
|
|
2
2
|
import { bytesFrom } from "../../bytes/index.js";
|
|
3
|
-
import { Transaction, TransactionLike } from "../../ckb/index.js";
|
|
4
|
-
import { Client, KnownScript } from "../../client/index.js";
|
|
3
|
+
import { Script, Transaction, TransactionLike } from "../../ckb/index.js";
|
|
4
|
+
import { CellDepInfo, Client, KnownScript } from "../../client/index.js";
|
|
5
5
|
import { hashCkb } from "../../hasher/index.js";
|
|
6
6
|
import { Hex, HexLike, hexFrom } from "../../hex/index.js";
|
|
7
7
|
import { Signer, SignerSignType, SignerType } from "../signer/index.js";
|
|
@@ -43,24 +43,109 @@ export class SignerCkbPublicKey extends Signer {
|
|
|
43
43
|
return this.publicKey;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
async getAddressObjSecp256k1(): Promise<Address> {
|
|
47
|
+
return Address.fromKnownScript(
|
|
48
|
+
this.client,
|
|
49
|
+
KnownScript.Secp256k1Blake160,
|
|
50
|
+
bytesFrom(hashCkb(this.publicKey)).slice(0, 20),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getRecommendedAddressObj(_preference?: unknown): Promise<Address> {
|
|
55
|
+
return this.getAddressObjSecp256k1();
|
|
56
|
+
}
|
|
57
|
+
|
|
46
58
|
async getAddressObjs(): Promise<Address[]> {
|
|
47
|
-
|
|
48
|
-
|
|
59
|
+
const secp256k1 = await this.getAddressObjSecp256k1();
|
|
60
|
+
|
|
61
|
+
const addresses: Address[] = [];
|
|
62
|
+
let count = 0;
|
|
63
|
+
for await (const cell of this.client.findCells({
|
|
64
|
+
script: await Script.fromKnownScript(
|
|
49
65
|
this.client,
|
|
50
|
-
KnownScript.
|
|
51
|
-
|
|
66
|
+
KnownScript.AnyoneCanPay,
|
|
67
|
+
secp256k1.script.args,
|
|
52
68
|
),
|
|
53
|
-
|
|
69
|
+
scriptType: "lock",
|
|
70
|
+
scriptSearchMode: "prefix",
|
|
71
|
+
withData: false,
|
|
72
|
+
})) {
|
|
73
|
+
if (count >= 10) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
count += 1;
|
|
77
|
+
|
|
78
|
+
if (addresses.some(({ script }) => script.eq(cell.cellOutput.lock))) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
addresses.push(
|
|
83
|
+
Address.from({
|
|
84
|
+
prefix: this.client.addressPrefix,
|
|
85
|
+
script: cell.cellOutput.lock,
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return [secp256k1, ...addresses];
|
|
54
91
|
}
|
|
55
92
|
|
|
56
|
-
async
|
|
93
|
+
async getRelatedScripts(
|
|
94
|
+
txLike: TransactionLike,
|
|
95
|
+
): Promise<{ script: Script; cellDeps: CellDepInfo[] }[]> {
|
|
57
96
|
const tx = Transaction.from(txLike);
|
|
58
|
-
|
|
59
|
-
await
|
|
97
|
+
|
|
98
|
+
const secp256k1 = await this.getAddressObjSecp256k1();
|
|
99
|
+
const acp = await Script.fromKnownScript(
|
|
60
100
|
this.client,
|
|
61
|
-
KnownScript.
|
|
101
|
+
KnownScript.AnyoneCanPay,
|
|
102
|
+
secp256k1.script.args,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const scripts: { script: Script; cellDeps: CellDepInfo[] }[] = [];
|
|
106
|
+
for (const input of tx.inputs) {
|
|
107
|
+
await input.completeExtraInfos(this.client);
|
|
108
|
+
if (!input.cellOutput) {
|
|
109
|
+
throw new Error("Unable to complete input");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const { lock } = input.cellOutput;
|
|
113
|
+
if (scripts.some(({ script }) => script.eq(lock))) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (lock.eq(secp256k1.script)) {
|
|
118
|
+
scripts.push({
|
|
119
|
+
script: lock,
|
|
120
|
+
cellDeps: (
|
|
121
|
+
await this.client.getKnownScript(KnownScript.Secp256k1Blake160)
|
|
122
|
+
).cellDeps,
|
|
123
|
+
});
|
|
124
|
+
} else if (
|
|
125
|
+
lock.codeHash === acp.codeHash &&
|
|
126
|
+
lock.hashType === acp.hashType &&
|
|
127
|
+
lock.args.startsWith(acp.args)
|
|
128
|
+
) {
|
|
129
|
+
scripts.push({
|
|
130
|
+
script: lock,
|
|
131
|
+
cellDeps: (await this.client.getKnownScript(KnownScript.AnyoneCanPay))
|
|
132
|
+
.cellDeps,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return scripts;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async prepareTransaction(txLike: TransactionLike): Promise<Transaction> {
|
|
141
|
+
const tx = Transaction.from(txLike);
|
|
142
|
+
|
|
143
|
+
await Promise.all(
|
|
144
|
+
(await this.getRelatedScripts(tx)).map(async ({ script, cellDeps }) => {
|
|
145
|
+
await tx.prepareSighashAllWitness(script, 65, this.client);
|
|
146
|
+
await tx.addCellDepInfos(this.client, cellDeps);
|
|
147
|
+
}),
|
|
62
148
|
);
|
|
63
|
-
await tx.prepareSighashAllWitness(script, 65, this.client);
|
|
64
149
|
return tx;
|
|
65
150
|
}
|
|
66
151
|
}
|