@ckb-ccc/core 1.14.0 → 1.15.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 +34 -0
- package/dist/address.advanced-BHxWrbFc.mjs +2 -0
- package/dist/address.advanced-BHxWrbFc.mjs.map +1 -0
- package/dist/advanced.d.mts +1 -1
- package/dist/advanced.mjs +1 -1
- package/{dist.commonjs/advancedBarrel-DRDT4GBS.d.ts → dist/advancedBarrel-Dwyn3WMm.d.mts} +437 -14
- package/dist/advancedBarrel-Dwyn3WMm.d.mts.map +1 -0
- package/dist/advancedBarrel.d.mts +1 -1
- package/dist/advancedBarrel.mjs +1 -1
- package/dist/barrel-DO-IW8Ui.mjs +7 -0
- package/dist/barrel-DO-IW8Ui.mjs.map +1 -0
- package/dist/barrel.d.mts +2 -2
- package/dist/barrel.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist.commonjs/address.advanced-UCU9Hn8t.js +2 -0
- package/dist.commonjs/address.advanced-UCU9Hn8t.js.map +1 -0
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +1 -1
- package/{dist/advancedBarrel-BD7EAPVd.d.mts → dist.commonjs/advancedBarrel-D97MfkUZ.d.ts} +438 -13
- package/dist.commonjs/advancedBarrel-D97MfkUZ.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +1 -1
- package/dist.commonjs/barrel-D5PRJCB6.js +21 -0
- package/dist.commonjs/barrel-D5PRJCB6.js.map +1 -0
- package/dist.commonjs/barrel.d.ts +2 -2
- package/dist.commonjs/barrel.js +1 -1
- package/dist.commonjs/index.d.ts +2 -2
- package/dist.commonjs/index.js +1 -1
- package/package.json +1 -1
- package/src/ckb/transaction.ts +20 -1
- package/src/client/clientPublicMainnet.advanced.ts +17 -0
- package/src/client/clientPublicTestnet.advanced.ts +17 -0
- package/src/client/knownScript.ts +1 -0
- package/src/codec/entity.ts +11 -5
- package/src/hasher/hasherCkb.ts +7 -1
- package/src/hex/index.ts +82 -2
- package/src/num/index.ts +17 -4
- package/src/signer/ckb/index.ts +3 -1
- package/src/signer/ckb/secp256k1Signing.ts +94 -0
- package/src/signer/ckb/signerCkbPrivateKey.ts +6 -11
- package/src/signer/ckb/signerCkbPublicKey.ts +8 -3
- package/src/signer/ckb/signerMultisigCkbPrivateKey.ts +129 -0
- package/src/signer/ckb/signerMultisigCkbReadonly.ts +713 -0
- package/src/signer/signer/index.ts +100 -1
- package/dist/address.advanced-BmJKF_Lg.mjs +0 -2
- package/dist/address.advanced-BmJKF_Lg.mjs.map +0 -1
- package/dist/advancedBarrel-BD7EAPVd.d.mts.map +0 -1
- package/dist/barrel-C-sr5NLL.mjs +0 -7
- package/dist/barrel-C-sr5NLL.mjs.map +0 -1
- package/dist.commonjs/address.advanced-D9nKvIr3.js +0 -2
- package/dist.commonjs/address.advanced-D9nKvIr3.js.map +0 -1
- package/dist.commonjs/advancedBarrel-DRDT4GBS.d.ts.map +0 -1
- package/dist.commonjs/barrel-SuR9mcfv.js +0 -21
- package/dist.commonjs/barrel-SuR9mcfv.js.map +0 -1
- package/src/signer/ckb/verifyCkbSecp256k1.ts +0 -31
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { SinceLike, Transaction, TransactionLike } from "../../ckb/index.js";
|
|
2
|
+
import { Client, KnownScript, ScriptInfoLike } from "../../client/index.js";
|
|
3
|
+
import { hashCkbShort } from "../../hasher/index.js";
|
|
4
|
+
import { Hex, hexFrom, HexLike } from "../../hex/index.js";
|
|
5
|
+
import { signMessageSecp256k1 } from "./secp256k1Signing.js";
|
|
6
|
+
import { SignerCkbPrivateKey } from "./signerCkbPrivateKey.js";
|
|
7
|
+
import {
|
|
8
|
+
MultisigCkbWitnessLike,
|
|
9
|
+
SignerMultisigCkbReadonly,
|
|
10
|
+
} from "./signerMultisigCkbReadonly.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A class extending Signer that provides access to a CKB multisig script and supports signing operations.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export class SignerMultisigCkbPrivateKey extends SignerMultisigCkbReadonly {
|
|
17
|
+
private readonly privateKey: Hex;
|
|
18
|
+
private readonly signer: SignerCkbPrivateKey;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates an instance of SignerMultisigCkbPrivateKey.
|
|
22
|
+
*
|
|
23
|
+
* @param client - The client instance.
|
|
24
|
+
* @param privateKey - The private key.
|
|
25
|
+
* @param multisigInfo - The multisig information.
|
|
26
|
+
* @param options - The options.
|
|
27
|
+
*/
|
|
28
|
+
constructor(
|
|
29
|
+
client: Client,
|
|
30
|
+
privateKey: HexLike,
|
|
31
|
+
multisigInfo: MultisigCkbWitnessLike,
|
|
32
|
+
options?: {
|
|
33
|
+
since?: SinceLike | null;
|
|
34
|
+
scriptInfos?: (KnownScript | ScriptInfoLike)[] | null;
|
|
35
|
+
} | null,
|
|
36
|
+
) {
|
|
37
|
+
super(client, multisigInfo, options);
|
|
38
|
+
|
|
39
|
+
this.privateKey = hexFrom(privateKey);
|
|
40
|
+
this.signer = new SignerCkbPrivateKey(client, this.privateKey);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Sign a transaction only (without preparing).
|
|
45
|
+
*
|
|
46
|
+
* @param txLike - The transaction to sign.
|
|
47
|
+
* @returns The signed transaction.
|
|
48
|
+
*/
|
|
49
|
+
async signOnlyTransaction(txLike: TransactionLike): Promise<Transaction> {
|
|
50
|
+
let tx = Transaction.from(txLike);
|
|
51
|
+
|
|
52
|
+
const thisPubkeyHash = hashCkbShort(this.signer.publicKey);
|
|
53
|
+
|
|
54
|
+
const index = this.multisigInfo.publicKeyHashes.indexOf(thisPubkeyHash);
|
|
55
|
+
if (index === -1) {
|
|
56
|
+
return tx;
|
|
57
|
+
}
|
|
58
|
+
const isSelfRequired = index < this.multisigInfo.mustMatch;
|
|
59
|
+
|
|
60
|
+
for (const { script } of await this.scriptInfos) {
|
|
61
|
+
const info = await this.getSignInfo(tx, script);
|
|
62
|
+
if (!info) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// === Find a position for the signature ===
|
|
67
|
+
tx = await this.prepareWitnessArgsAt(
|
|
68
|
+
tx,
|
|
69
|
+
info.position,
|
|
70
|
+
async (witness) => {
|
|
71
|
+
// We re-evaluate the signatures to filter invalid / excessive signatures
|
|
72
|
+
const signatures: Hex[] = [];
|
|
73
|
+
let requiredCount = 0;
|
|
74
|
+
let isSignNeeded = true;
|
|
75
|
+
|
|
76
|
+
for (const {
|
|
77
|
+
pubkeyHash,
|
|
78
|
+
signature,
|
|
79
|
+
isRequired,
|
|
80
|
+
} of witness.generatePublicKeyHashesFromSignatures(info.message)) {
|
|
81
|
+
if (pubkeyHash === thisPubkeyHash) {
|
|
82
|
+
if (!isSignNeeded) {
|
|
83
|
+
// Has signed and added to the signatures list already. We will not add it again.
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
isSignNeeded = false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (isRequired) {
|
|
90
|
+
requiredCount += 1;
|
|
91
|
+
} else if (
|
|
92
|
+
signatures.length - requiredCount >=
|
|
93
|
+
this.multisigInfo.flexibleThreshold
|
|
94
|
+
) {
|
|
95
|
+
// Too many flexible signatures
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
signatures.push(signature);
|
|
100
|
+
if (signatures.length >= this.multisigInfo.threshold) {
|
|
101
|
+
// We have got enough signatures
|
|
102
|
+
isSignNeeded = false;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (
|
|
108
|
+
isSignNeeded &&
|
|
109
|
+
(isSelfRequired ||
|
|
110
|
+
signatures.length - requiredCount <
|
|
111
|
+
this.multisigInfo.flexibleThreshold)
|
|
112
|
+
) {
|
|
113
|
+
// Add the signature from this signer only when
|
|
114
|
+
// 1. The signature is needed
|
|
115
|
+
// 2. It's required or...
|
|
116
|
+
// 3. We haven't got enough flexible signatures
|
|
117
|
+
signatures.push(
|
|
118
|
+
signMessageSecp256k1(info.message, this.privateKey),
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
witness.signatures = signatures;
|
|
122
|
+
return witness;
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return tx;
|
|
128
|
+
}
|
|
129
|
+
}
|