@ckb-ccc/core 0.0.3 → 0.0.4-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/dist/signer/btc/index.d.ts +3 -0
- package/dist/signer/btc/index.d.ts.map +1 -0
- package/dist/signer/btc/index.js +2 -0
- package/dist/signer/btc/signerBtc.d.ts +12 -0
- package/dist/signer/btc/signerBtc.d.ts.map +1 -0
- package/dist/signer/btc/signerBtc.js +35 -0
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +12 -0
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -0
- package/dist/signer/btc/signerBtcPublicKeyReadonly.js +16 -0
- package/dist/signer/ckb/index.d.ts +2 -0
- package/dist/signer/ckb/index.d.ts.map +1 -0
- package/dist/signer/ckb/index.js +1 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +12 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.js +16 -0
- package/dist/signer/evm/index.d.ts +3 -0
- package/dist/signer/evm/index.d.ts.map +1 -0
- package/dist/signer/evm/index.js +2 -0
- package/dist/signer/evm/signerEvm.d.ts +10 -0
- package/dist/signer/evm/signerEvm.d.ts.map +1 -0
- package/dist/signer/evm/signerEvm.js +34 -0
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts +10 -0
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -0
- package/dist/signer/evm/signerEvmAddressReadonly.js +12 -0
- package/dist/signer/index.d.ts +3 -2
- package/dist/signer/index.d.ts.map +1 -1
- package/dist/signer/index.js +3 -2
- package/dist/signer/signer.d.ts +16 -2
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +17 -0
- package/package.json +3 -2
- package/src/signer/btc/index.ts +2 -0
- package/src/signer/btc/signerBtc.ts +65 -0
- package/src/signer/btc/signerBtcPublicKeyReadonly.ts +27 -0
- package/src/signer/ckb/index.ts +1 -0
- package/src/signer/ckb/signerCkbScriptReadonly.ts +24 -0
- package/src/signer/evm/index.ts +2 -0
- package/src/signer/evm/signerEvm.ts +58 -0
- package/src/signer/evm/signerEvmAddressReadonly.ts +19 -0
- package/src/signer/index.ts +3 -2
- package/src/signer/signer.ts +24 -2
- package/dist/signer/signerReadonly.d.ts +0 -7
- package/dist/signer/signerReadonly.d.ts.map +0 -1
- package/dist/signer/signerReadonly.js +0 -9
- package/dist/signer/signerReadonlyCkbScript.d.ts +0 -12
- package/dist/signer/signerReadonlyCkbScript.d.ts.map +0 -1
- package/dist/signer/signerReadonlyCkbScript.js +0 -17
- package/src/signer/signerReadonly.ts +0 -12
- package/src/signer/signerReadonlyCkbScript.ts +0 -25
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Address } from "../../address";
|
|
2
|
+
import { Transaction } from "../../ckb";
|
|
3
|
+
import { HexLike } from "../../hex";
|
|
4
|
+
import { Signer } from "../signer";
|
|
5
|
+
export declare abstract class SignerBtc extends Signer {
|
|
6
|
+
abstract getBtcAccount(): Promise<string>;
|
|
7
|
+
abstract getBtcPublicKey(): Promise<HexLike>;
|
|
8
|
+
getInternalAddress(): Promise<string>;
|
|
9
|
+
getAddressObjs(): Promise<Address[]>;
|
|
10
|
+
signOnlyTransaction(tx: Transaction): Promise<Transaction>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=signerBtc.d.ts.map
|
|
@@ -0,0 +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,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,8BAAsB,SAAU,SAAQ,MAAM;IAC5C,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC,QAAQ,CAAC,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAEtC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAapC,mBAAmB,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;CA+BjE"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ripemd160 } from "@noble/hashes/ripemd160";
|
|
2
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
3
|
+
import { Address } from "../../address";
|
|
4
|
+
import { bytesConcat, bytesFrom } from "../../bytes";
|
|
5
|
+
import { WitnessArgs } from "../../ckb";
|
|
6
|
+
import { KnownScript } from "../../client";
|
|
7
|
+
import { hexFrom } from "../../hex";
|
|
8
|
+
import { numToBytes } from "../../num";
|
|
9
|
+
import { getSignHashInfo } from "../helpers";
|
|
10
|
+
import { Signer } from "../signer";
|
|
11
|
+
export class SignerBtc extends Signer {
|
|
12
|
+
async getInternalAddress() {
|
|
13
|
+
return this.getBtcAccount();
|
|
14
|
+
}
|
|
15
|
+
async getAddressObjs() {
|
|
16
|
+
const publicKey = await this.getBtcPublicKey();
|
|
17
|
+
const hash = ripemd160(sha256(bytesFrom(publicKey)));
|
|
18
|
+
return [
|
|
19
|
+
await Address.fromKnownScript(KnownScript.OmniLock, hexFrom([0x04, ...hash, 0x00]), this.client),
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
async signOnlyTransaction(tx) {
|
|
23
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
24
|
+
const info = await getSignHashInfo(tx, script);
|
|
25
|
+
if (!info) {
|
|
26
|
+
return tx;
|
|
27
|
+
}
|
|
28
|
+
const signature = bytesFrom(await this.signMessage(`CKB (Bitcoin Layer) transaction: ${info.message}`), "base64");
|
|
29
|
+
signature[0] = 31 + ((signature[0] - 27) % 4);
|
|
30
|
+
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
31
|
+
witness.lock = hexFrom(bytesConcat(numToBytes(5 * 4 + signature.length, 4), numToBytes(4 * 4, 4), numToBytes(5 * 4 + signature.length, 4), numToBytes(5 * 4 + signature.length, 4), numToBytes(signature.length, 4), signature));
|
|
32
|
+
tx.witnesses[info.position] = hexFrom(witness.toBytes());
|
|
33
|
+
return tx;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Client } from "../../client";
|
|
2
|
+
import { Hex, HexLike } from "../../hex";
|
|
3
|
+
import { SignerBtc } from "./signerBtc";
|
|
4
|
+
export declare class SignerBtcPublicKeyReadonly extends SignerBtc {
|
|
5
|
+
private readonly account;
|
|
6
|
+
private readonly publicKey;
|
|
7
|
+
constructor(client: Client, account: string, publicKey: HexLike);
|
|
8
|
+
connect(): Promise<void>;
|
|
9
|
+
getBtcAccount(): Promise<string>;
|
|
10
|
+
getBtcPublicKey(): Promise<Hex>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=signerBtcPublicKeyReadonly.d.ts.map
|
|
@@ -0,0 +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,qBAAa,0BAA2B,SAAQ,SAAS;IAKrD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAM;gBAG9B,MAAM,EAAE,MAAM,EACG,OAAO,EAAE,MAAM,EAChC,SAAS,EAAE,OAAO;IAOd,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAExB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAIhC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC;CAGtC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { hexFrom } from "../../hex";
|
|
2
|
+
import { SignerBtc } from "./signerBtc";
|
|
3
|
+
export class SignerBtcPublicKeyReadonly extends SignerBtc {
|
|
4
|
+
constructor(client, account, publicKey) {
|
|
5
|
+
super(client);
|
|
6
|
+
this.account = account;
|
|
7
|
+
this.publicKey = hexFrom(publicKey);
|
|
8
|
+
}
|
|
9
|
+
async connect() { }
|
|
10
|
+
async getBtcAccount() {
|
|
11
|
+
return this.account;
|
|
12
|
+
}
|
|
13
|
+
async getBtcPublicKey() {
|
|
14
|
+
return this.publicKey;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./signerCkbScriptReadonly";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Address } from "../../address";
|
|
2
|
+
import { ScriptLike } from "../../ckb";
|
|
3
|
+
import { Client } from "../../client";
|
|
4
|
+
import { Signer } from "../signer";
|
|
5
|
+
export declare class SignerCkbScriptReadonly extends Signer {
|
|
6
|
+
private readonly script;
|
|
7
|
+
constructor(client: Client, script: ScriptLike);
|
|
8
|
+
connect(): Promise<void>;
|
|
9
|
+
getInternalAddress(): Promise<string>;
|
|
10
|
+
getAddressObjs(): Promise<Address[]>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=signerCkbScriptReadonly.d.ts.map
|
|
@@ -0,0 +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,qBAAa,uBAAwB,SAAQ,MAAM;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAMxC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAExB,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG3C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Address } from "../../address";
|
|
2
|
+
import { Script } from "../../ckb";
|
|
3
|
+
import { Signer } from "../signer";
|
|
4
|
+
export class SignerCkbScriptReadonly extends Signer {
|
|
5
|
+
constructor(client, script) {
|
|
6
|
+
super(client);
|
|
7
|
+
this.script = Script.from(script);
|
|
8
|
+
}
|
|
9
|
+
async connect() { }
|
|
10
|
+
async getInternalAddress() {
|
|
11
|
+
return this.getRecommendedAddress();
|
|
12
|
+
}
|
|
13
|
+
async getAddressObjs() {
|
|
14
|
+
return [await Address.fromScript(this.script, this.client)];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Address } from "../../address";
|
|
2
|
+
import { Transaction } from "../../ckb";
|
|
3
|
+
import { Signer } from "../signer";
|
|
4
|
+
export declare abstract class SignerEvm extends Signer {
|
|
5
|
+
abstract getEvmAccount(): Promise<string>;
|
|
6
|
+
getInternalAddress(): Promise<string>;
|
|
7
|
+
getAddressObjs(): Promise<Address[]>;
|
|
8
|
+
signOnlyTransaction(tx: Transaction): Promise<Transaction>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=signerEvm.d.ts.map
|
|
@@ -0,0 +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,MAAM,WAAW,CAAC;AAKrD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,8BAAsB,SAAU,SAAQ,MAAM;IAC5C,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEnC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAWpC,mBAAmB,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;CA8BjE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Address } from "../../address";
|
|
2
|
+
import { bytesConcat, bytesFrom } from "../../bytes";
|
|
3
|
+
import { WitnessArgs } from "../../ckb";
|
|
4
|
+
import { KnownScript } from "../../client";
|
|
5
|
+
import { hexFrom } from "../../hex";
|
|
6
|
+
import { numToBytes } from "../../num";
|
|
7
|
+
import { getSignHashInfo } from "../helpers";
|
|
8
|
+
import { Signer } from "../signer";
|
|
9
|
+
export class SignerEvm extends Signer {
|
|
10
|
+
async getInternalAddress() {
|
|
11
|
+
return this.getEvmAccount();
|
|
12
|
+
}
|
|
13
|
+
async getAddressObjs() {
|
|
14
|
+
const account = await this.getEvmAccount();
|
|
15
|
+
return [
|
|
16
|
+
await Address.fromKnownScript(KnownScript.OmniLock, hexFrom([0x12, ...bytesFrom(account), 0x00]), this.client),
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
async signOnlyTransaction(tx) {
|
|
20
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
21
|
+
const info = await getSignHashInfo(tx, script);
|
|
22
|
+
if (!info) {
|
|
23
|
+
return tx;
|
|
24
|
+
}
|
|
25
|
+
const signature = bytesFrom(await this.signMessage(`CKB transaction: ${info.message}`));
|
|
26
|
+
if (signature[signature.length - 1] >= 27) {
|
|
27
|
+
signature[signature.length - 1] -= 27;
|
|
28
|
+
}
|
|
29
|
+
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
30
|
+
witness.lock = hexFrom(bytesConcat(numToBytes(5 * 4 + signature.length, 4), numToBytes(4 * 4, 4), numToBytes(5 * 4 + signature.length, 4), numToBytes(5 * 4 + signature.length, 4), numToBytes(signature.length, 4), signature));
|
|
31
|
+
tx.witnesses[info.position] = hexFrom(witness.toBytes());
|
|
32
|
+
return tx;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Client } from "../../client";
|
|
2
|
+
import { HexLike } from "../../hex";
|
|
3
|
+
import { SignerEvm } from "./signerEvm";
|
|
4
|
+
export declare abstract class SignerEvmAddressReadonly extends SignerEvm {
|
|
5
|
+
private readonly address;
|
|
6
|
+
constructor(client: Client, address: HexLike);
|
|
7
|
+
connect(): Promise<void>;
|
|
8
|
+
getEvmAccount(): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=signerEvmAddressReadonly.d.ts.map
|
|
@@ -0,0 +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,8BAAsB,wBAAyB,SAAQ,SAAS;IAC9D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;gBAElB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAMtC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAExB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAGvC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { hexFrom } from "../../hex";
|
|
2
|
+
import { SignerEvm } from "./signerEvm";
|
|
3
|
+
export class SignerEvmAddressReadonly extends SignerEvm {
|
|
4
|
+
constructor(client, address) {
|
|
5
|
+
super(client);
|
|
6
|
+
this.address = hexFrom(address);
|
|
7
|
+
}
|
|
8
|
+
async connect() { }
|
|
9
|
+
async getEvmAccount() {
|
|
10
|
+
return this.address;
|
|
11
|
+
}
|
|
12
|
+
}
|
package/dist/signer/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signer/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signer/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
package/dist/signer/index.js
CHANGED
package/dist/signer/signer.d.ts
CHANGED
|
@@ -12,9 +12,23 @@ export declare abstract class Signer {
|
|
|
12
12
|
getRecommendedAddressObj(_preference?: unknown): Promise<Address>;
|
|
13
13
|
getRecommendedAddress(preference?: unknown): Promise<string>;
|
|
14
14
|
getAddresses(): Promise<string[]>;
|
|
15
|
-
|
|
15
|
+
signMessage(_: string | BytesLike): Promise<string>;
|
|
16
16
|
sendTransaction(tx: Transaction): Promise<Hex>;
|
|
17
17
|
signTransaction(tx: Transaction): Promise<Transaction>;
|
|
18
|
-
|
|
18
|
+
signOnlyTransaction(_: Transaction): Promise<Transaction>;
|
|
19
19
|
}
|
|
20
|
+
export declare enum SignerType {
|
|
21
|
+
EVM = "EVM",
|
|
22
|
+
BTC = "BTC"
|
|
23
|
+
}
|
|
24
|
+
export declare class SignerInfo {
|
|
25
|
+
type: SignerType;
|
|
26
|
+
signer: Signer;
|
|
27
|
+
constructor(type: SignerType, signer: Signer);
|
|
28
|
+
}
|
|
29
|
+
export type Wallet = {
|
|
30
|
+
name: string;
|
|
31
|
+
icon: string;
|
|
32
|
+
signers: SignerInfo[];
|
|
33
|
+
};
|
|
20
34
|
//# 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,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,8BAAsB,MAAM;aACE,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;IAE1C,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAEjC,QAAQ,CAAC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAE9C,QAAQ,CAAC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IACvC,wBAAwB,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjE,qBAAqB,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAG5D,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAMvC,
|
|
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,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,8BAAsB,MAAM;aACE,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;IAE1C,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAEjC,QAAQ,CAAC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAE9C,QAAQ,CAAC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IACvC,wBAAwB,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjE,qBAAqB,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAG5D,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAMvC,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAI7C,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAI9C,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAI5D,mBAAmB,CAAC,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;CAG1D;AAED,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED,qBAAa,UAAU;IAEZ,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,MAAM;gBADd,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM;CAExB;AAED,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
|
@@ -11,10 +11,27 @@ export class Signer {
|
|
|
11
11
|
async getAddresses() {
|
|
12
12
|
return this.getAddressObjs().then((addresses) => addresses.map((address) => address.toString()));
|
|
13
13
|
}
|
|
14
|
+
signMessage(_) {
|
|
15
|
+
throw Error("Signer.signMessage not implemented");
|
|
16
|
+
}
|
|
14
17
|
async sendTransaction(tx) {
|
|
15
18
|
return this.client.sendTransaction(await this.signTransaction(tx));
|
|
16
19
|
}
|
|
17
20
|
async signTransaction(tx) {
|
|
18
21
|
return this.signOnlyTransaction(tx);
|
|
19
22
|
}
|
|
23
|
+
signOnlyTransaction(_) {
|
|
24
|
+
throw Error("Signer.signOnlyTransaction not implemented");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export var SignerType;
|
|
28
|
+
(function (SignerType) {
|
|
29
|
+
SignerType["EVM"] = "EVM";
|
|
30
|
+
SignerType["BTC"] = "BTC";
|
|
31
|
+
})(SignerType || (SignerType = {}));
|
|
32
|
+
export class SignerInfo {
|
|
33
|
+
constructor(type, signer) {
|
|
34
|
+
this.type = type;
|
|
35
|
+
this.signer = signer;
|
|
36
|
+
}
|
|
20
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-alpha.0",
|
|
4
4
|
"description": "Common Chains Connector Core",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,11 +40,12 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"@noble/hashes": "^1.4.0",
|
|
43
44
|
"abort-controller": "^3.0.0",
|
|
44
45
|
"bech32": "^2.0.0",
|
|
45
46
|
"blake2b": "^2.1.4",
|
|
46
47
|
"buffer": "^6.0.3",
|
|
47
48
|
"cross-fetch": "^4.0.0"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "e49045ed4b2778c92d6f49b79c17125245141a21"
|
|
50
51
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ripemd160 } from "@noble/hashes/ripemd160";
|
|
2
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
3
|
+
import { Address } from "../../address";
|
|
4
|
+
import { bytesConcat, bytesFrom } from "../../bytes";
|
|
5
|
+
import { Transaction, WitnessArgs } from "../../ckb";
|
|
6
|
+
import { KnownScript } from "../../client";
|
|
7
|
+
import { HexLike, hexFrom } from "../../hex";
|
|
8
|
+
import { numToBytes } from "../../num";
|
|
9
|
+
import { getSignHashInfo } from "../helpers";
|
|
10
|
+
import { Signer } from "../signer";
|
|
11
|
+
|
|
12
|
+
export abstract class SignerBtc extends Signer {
|
|
13
|
+
abstract getBtcAccount(): Promise<string>;
|
|
14
|
+
|
|
15
|
+
abstract getBtcPublicKey(): Promise<HexLike>;
|
|
16
|
+
|
|
17
|
+
async getInternalAddress(): Promise<string> {
|
|
18
|
+
return this.getBtcAccount();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async getAddressObjs(): Promise<Address[]> {
|
|
22
|
+
const publicKey = await this.getBtcPublicKey();
|
|
23
|
+
const hash = ripemd160(sha256(bytesFrom(publicKey)));
|
|
24
|
+
|
|
25
|
+
return [
|
|
26
|
+
await Address.fromKnownScript(
|
|
27
|
+
KnownScript.OmniLock,
|
|
28
|
+
hexFrom([0x04, ...hash, 0x00]),
|
|
29
|
+
this.client,
|
|
30
|
+
),
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async signOnlyTransaction(tx: Transaction): Promise<Transaction> {
|
|
35
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
36
|
+
const info = await getSignHashInfo(tx, script);
|
|
37
|
+
if (!info) {
|
|
38
|
+
return tx;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const signature = bytesFrom(
|
|
42
|
+
await this.signMessage(
|
|
43
|
+
`CKB (Bitcoin Layer) transaction: ${info.message}`,
|
|
44
|
+
),
|
|
45
|
+
"base64",
|
|
46
|
+
);
|
|
47
|
+
signature[0] = 31 + ((signature[0] - 27) % 4);
|
|
48
|
+
|
|
49
|
+
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
50
|
+
witness.lock = hexFrom(
|
|
51
|
+
bytesConcat(
|
|
52
|
+
numToBytes(5 * 4 + signature.length, 4),
|
|
53
|
+
numToBytes(4 * 4, 4),
|
|
54
|
+
numToBytes(5 * 4 + signature.length, 4),
|
|
55
|
+
numToBytes(5 * 4 + signature.length, 4),
|
|
56
|
+
numToBytes(signature.length, 4),
|
|
57
|
+
signature,
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
tx.witnesses[info.position] = hexFrom(witness.toBytes());
|
|
62
|
+
|
|
63
|
+
return tx;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Client } from "../../client";
|
|
2
|
+
import { Hex, HexLike, hexFrom } from "../../hex";
|
|
3
|
+
import { SignerBtc } from "./signerBtc";
|
|
4
|
+
|
|
5
|
+
export class SignerBtcPublicKeyReadonly extends SignerBtc {
|
|
6
|
+
private readonly publicKey: Hex;
|
|
7
|
+
|
|
8
|
+
constructor(
|
|
9
|
+
client: Client,
|
|
10
|
+
private readonly account: string,
|
|
11
|
+
publicKey: HexLike,
|
|
12
|
+
) {
|
|
13
|
+
super(client);
|
|
14
|
+
|
|
15
|
+
this.publicKey = hexFrom(publicKey);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async connect(): Promise<void> {}
|
|
19
|
+
|
|
20
|
+
async getBtcAccount(): Promise<string> {
|
|
21
|
+
return this.account;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async getBtcPublicKey(): Promise<Hex> {
|
|
25
|
+
return this.publicKey;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./signerCkbScriptReadonly";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Address } from "../../address";
|
|
2
|
+
import { Script, ScriptLike } from "../../ckb";
|
|
3
|
+
import { Client } from "../../client";
|
|
4
|
+
import { Signer } from "../signer";
|
|
5
|
+
|
|
6
|
+
export class SignerCkbScriptReadonly extends Signer {
|
|
7
|
+
private readonly script: Script;
|
|
8
|
+
|
|
9
|
+
constructor(client: Client, script: ScriptLike) {
|
|
10
|
+
super(client);
|
|
11
|
+
|
|
12
|
+
this.script = Script.from(script);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async connect(): Promise<void> {}
|
|
16
|
+
|
|
17
|
+
async getInternalAddress(): Promise<string> {
|
|
18
|
+
return this.getRecommendedAddress();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async getAddressObjs(): Promise<Address[]> {
|
|
22
|
+
return [await Address.fromScript(this.script, this.client)];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Address } from "../../address";
|
|
2
|
+
import { bytesConcat, bytesFrom } from "../../bytes";
|
|
3
|
+
import { Transaction, WitnessArgs } from "../../ckb";
|
|
4
|
+
import { KnownScript } from "../../client";
|
|
5
|
+
import { hexFrom } from "../../hex";
|
|
6
|
+
import { numToBytes } from "../../num";
|
|
7
|
+
import { getSignHashInfo } from "../helpers";
|
|
8
|
+
import { Signer } from "../signer";
|
|
9
|
+
|
|
10
|
+
export abstract class SignerEvm extends Signer {
|
|
11
|
+
abstract getEvmAccount(): Promise<string>;
|
|
12
|
+
|
|
13
|
+
async getInternalAddress(): Promise<string> {
|
|
14
|
+
return this.getEvmAccount();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getAddressObjs(): Promise<Address[]> {
|
|
18
|
+
const account = await this.getEvmAccount();
|
|
19
|
+
return [
|
|
20
|
+
await Address.fromKnownScript(
|
|
21
|
+
KnownScript.OmniLock,
|
|
22
|
+
hexFrom([0x12, ...bytesFrom(account), 0x00]),
|
|
23
|
+
this.client,
|
|
24
|
+
),
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async signOnlyTransaction(tx: Transaction): Promise<Transaction> {
|
|
29
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
30
|
+
const info = await getSignHashInfo(tx, script);
|
|
31
|
+
if (!info) {
|
|
32
|
+
return tx;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const signature = bytesFrom(
|
|
36
|
+
await this.signMessage(`CKB transaction: ${info.message}`),
|
|
37
|
+
);
|
|
38
|
+
if (signature[signature.length - 1] >= 27) {
|
|
39
|
+
signature[signature.length - 1] -= 27;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
43
|
+
witness.lock = hexFrom(
|
|
44
|
+
bytesConcat(
|
|
45
|
+
numToBytes(5 * 4 + signature.length, 4),
|
|
46
|
+
numToBytes(4 * 4, 4),
|
|
47
|
+
numToBytes(5 * 4 + signature.length, 4),
|
|
48
|
+
numToBytes(5 * 4 + signature.length, 4),
|
|
49
|
+
numToBytes(signature.length, 4),
|
|
50
|
+
signature,
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
tx.witnesses[info.position] = hexFrom(witness.toBytes());
|
|
55
|
+
|
|
56
|
+
return tx;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Client } from "../../client";
|
|
2
|
+
import { Hex, HexLike, hexFrom } from "../../hex";
|
|
3
|
+
import { SignerEvm } from "./signerEvm";
|
|
4
|
+
|
|
5
|
+
export abstract class SignerEvmAddressReadonly extends SignerEvm {
|
|
6
|
+
private readonly address: Hex;
|
|
7
|
+
|
|
8
|
+
constructor(client: Client, address: HexLike) {
|
|
9
|
+
super(client);
|
|
10
|
+
|
|
11
|
+
this.address = hexFrom(address);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async connect(): Promise<void> {}
|
|
15
|
+
|
|
16
|
+
async getEvmAccount(): Promise<string> {
|
|
17
|
+
return this.address;
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/signer/index.ts
CHANGED
package/src/signer/signer.ts
CHANGED
|
@@ -25,7 +25,9 @@ export abstract class Signer {
|
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
signMessage(_: string | BytesLike): Promise<string> {
|
|
29
|
+
throw Error("Signer.signMessage not implemented");
|
|
30
|
+
}
|
|
29
31
|
|
|
30
32
|
async sendTransaction(tx: Transaction): Promise<Hex> {
|
|
31
33
|
return this.client.sendTransaction(await this.signTransaction(tx));
|
|
@@ -35,5 +37,25 @@ export abstract class Signer {
|
|
|
35
37
|
return this.signOnlyTransaction(tx);
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
signOnlyTransaction(_: Transaction): Promise<Transaction> {
|
|
41
|
+
throw Error("Signer.signOnlyTransaction not implemented");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export enum SignerType {
|
|
46
|
+
EVM = "EVM",
|
|
47
|
+
BTC = "BTC",
|
|
39
48
|
}
|
|
49
|
+
|
|
50
|
+
export class SignerInfo {
|
|
51
|
+
constructor(
|
|
52
|
+
public type: SignerType,
|
|
53
|
+
public signer: Signer,
|
|
54
|
+
) {}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type Wallet = {
|
|
58
|
+
name: string;
|
|
59
|
+
icon: string;
|
|
60
|
+
signers: SignerInfo[];
|
|
61
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signerReadonly.d.ts","sourceRoot":"","sources":["../../src/signer/signerReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,8BAAsB,cAAe,SAAQ,MAAM;IACjD,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B,mBAAmB,IAAI,OAAO,CAAC,WAAW,CAAC;CAG5C"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Address } from "../address";
|
|
2
|
-
import { Script } from "../ckb";
|
|
3
|
-
import { Client } from "../client";
|
|
4
|
-
import { SignerReadonly } from "./signerReadonly";
|
|
5
|
-
export declare class SignerReadonlyCkbScript extends SignerReadonly {
|
|
6
|
-
private readonly script;
|
|
7
|
-
constructor(script: Script, client: Client);
|
|
8
|
-
connect(): Promise<void>;
|
|
9
|
-
getInternalAddress(): Promise<string>;
|
|
10
|
-
getAddressObjs(): Promise<Address[]>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=signerReadonlyCkbScript.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signerReadonlyCkbScript.d.ts","sourceRoot":"","sources":["../../src/signer/signerReadonlyCkbScript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,uBAAwB,SAAQ,cAAc;IAEvD,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM,EAC/B,MAAM,EAAE,MAAM;IAKV,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG3C"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Address } from "../address";
|
|
2
|
-
import { SignerReadonly } from "./signerReadonly";
|
|
3
|
-
export class SignerReadonlyCkbScript extends SignerReadonly {
|
|
4
|
-
constructor(script, client) {
|
|
5
|
-
super(client);
|
|
6
|
-
this.script = script;
|
|
7
|
-
}
|
|
8
|
-
async connect() {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
async getInternalAddress() {
|
|
12
|
-
return this.getRecommendedAddress();
|
|
13
|
-
}
|
|
14
|
-
async getAddressObjs() {
|
|
15
|
-
return [await Address.fromScript(this.script, this.client)];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Signer } from ".";
|
|
2
|
-
import { Transaction } from "../ckb";
|
|
3
|
-
|
|
4
|
-
export abstract class SignerReadonly extends Signer {
|
|
5
|
-
signMessage(): Promise<string> {
|
|
6
|
-
throw new Error("Method not implemented.");
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
signOnlyTransaction(): Promise<Transaction> {
|
|
10
|
-
throw new Error("Method not implemented.");
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Address } from "../address";
|
|
2
|
-
import { Script } from "../ckb";
|
|
3
|
-
import { Client } from "../client";
|
|
4
|
-
import { SignerReadonly } from "./signerReadonly";
|
|
5
|
-
|
|
6
|
-
export class SignerReadonlyCkbScript extends SignerReadonly {
|
|
7
|
-
constructor(
|
|
8
|
-
private readonly script: Script,
|
|
9
|
-
client: Client,
|
|
10
|
-
) {
|
|
11
|
-
super(client);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async connect(): Promise<void> {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async getInternalAddress(): Promise<string> {
|
|
19
|
-
return this.getRecommendedAddress();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async getAddressObjs(): Promise<Address[]> {
|
|
23
|
-
return [await Address.fromScript(this.script, this.client)];
|
|
24
|
-
}
|
|
25
|
-
}
|