@ckb-ccc/core 0.0.5-alpha.0 → 0.0.5-alpha.2
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/address/index.d.ts +1 -1
- package/dist/address/index.d.ts.map +1 -1
- package/dist/address/index.js +4 -4
- package/dist/client/client.d.ts +6 -3
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +15 -0
- package/dist/client/clientPublicMainnet.d.ts +1 -1
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.js +1 -1
- package/dist/client/clientPublicTestnet.d.ts +1 -1
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +1 -1
- package/dist/client/jsonRpc/index.d.ts +15 -5
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +16 -6
- package/dist/signer/btc/index.d.ts +1 -0
- package/dist/signer/btc/index.d.ts.map +1 -1
- package/dist/signer/btc/index.js +1 -0
- package/dist/signer/btc/signerBtc.d.ts +9 -1
- package/dist/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist/signer/btc/signerBtc.js +16 -2
- package/dist/signer/btc/verify.d.ts +3 -0
- package/dist/signer/btc/verify.d.ts.map +1 -0
- package/dist/signer/btc/verify.js +6 -0
- package/dist/signer/ckb/index.d.ts +1 -0
- package/dist/signer/ckb/index.d.ts.map +1 -1
- package/dist/signer/ckb/index.js +1 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +3 -1
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist/signer/ckb/signerCkbScriptReadonly.js +8 -2
- package/dist/signer/ckb/verifyJoyId.d.ts +3 -0
- package/dist/signer/ckb/verifyJoyId.d.ts.map +1 -0
- package/dist/signer/ckb/verifyJoyId.js +12 -0
- package/dist/signer/evm/index.d.ts +1 -0
- package/dist/signer/evm/index.d.ts.map +1 -1
- package/dist/signer/evm/index.js +1 -0
- package/dist/signer/evm/signerEvm.d.ts +3 -1
- package/dist/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist/signer/evm/signerEvm.js +8 -2
- package/dist/signer/evm/verify.d.ts +3 -0
- package/dist/signer/evm/verify.d.ts.map +1 -0
- package/dist/signer/evm/verify.js +6 -0
- package/dist/signer/signer.d.ts +67 -14
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +103 -16
- package/dist.commonjs/address/index.d.ts +1 -1
- package/dist.commonjs/address/index.d.ts.map +1 -1
- package/dist.commonjs/address/index.js +4 -4
- package/dist.commonjs/client/client.d.ts +6 -3
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +15 -0
- package/dist.commonjs/client/clientPublicMainnet.d.ts +1 -1
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.js +1 -1
- package/dist.commonjs/client/clientPublicTestnet.d.ts +1 -1
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.js +1 -1
- package/dist.commonjs/client/jsonRpc/index.d.ts +15 -5
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +15 -5
- package/dist.commonjs/signer/btc/index.d.ts +1 -0
- package/dist.commonjs/signer/btc/index.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/index.js +1 -0
- package/dist.commonjs/signer/btc/signerBtc.d.ts +9 -1
- package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/signerBtc.js +15 -1
- package/dist.commonjs/signer/btc/verify.d.ts +3 -0
- package/dist.commonjs/signer/btc/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/verify.js +10 -0
- package/dist.commonjs/signer/ckb/index.d.ts +1 -0
- package/dist.commonjs/signer/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/index.js +1 -0
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +3 -1
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +7 -1
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +3 -0
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/verifyJoyId.js +16 -0
- package/dist.commonjs/signer/evm/index.d.ts +1 -0
- package/dist.commonjs/signer/evm/index.d.ts.map +1 -1
- package/dist.commonjs/signer/evm/index.js +1 -0
- package/dist.commonjs/signer/evm/signerEvm.d.ts +3 -1
- package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist.commonjs/signer/evm/signerEvm.js +7 -1
- package/dist.commonjs/signer/evm/verify.d.ts +3 -0
- package/dist.commonjs/signer/evm/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/verify.js +10 -0
- package/dist.commonjs/signer/signer.d.ts +67 -14
- package/dist.commonjs/signer/signer.d.ts.map +1 -1
- package/dist.commonjs/signer/signer.js +105 -17
- package/package.json +6 -3
- package/src/address/index.ts +4 -7
- package/src/client/client.ts +26 -3
- package/src/client/clientPublicMainnet.ts +1 -1
- package/src/client/clientPublicTestnet.ts +1 -1
- package/src/client/jsonRpc/index.ts +21 -5
- package/src/signer/btc/index.ts +1 -0
- package/src/signer/btc/signerBtc.ts +19 -2
- package/src/signer/btc/verify.ts +14 -0
- package/src/signer/ckb/index.ts +1 -0
- package/src/signer/ckb/signerCkbScriptReadonly.ts +10 -2
- package/src/signer/ckb/verifyJoyId.ts +20 -0
- package/src/signer/evm/index.ts +1 -0
- package/src/signer/evm/signerEvm.ts +10 -2
- package/src/signer/evm/verify.ts +16 -0
- package/src/signer/signer.ts +137 -15
- package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +0 -1
package/dist/address/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare class Address {
|
|
|
42
42
|
* @param client - The client instance used to fetch the address prefix.
|
|
43
43
|
* @returns A promise that resolves to an Address instance.
|
|
44
44
|
*/
|
|
45
|
-
static fromScript(script: ScriptLike, client: Client):
|
|
45
|
+
static fromScript(script: ScriptLike, client: Client): Address;
|
|
46
46
|
static fromKnownScript(script: KnownScript, args: HexLike, client: Client): Promise<Address>;
|
|
47
47
|
/**
|
|
48
48
|
* Converts the Address instance to a string.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/address/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAmB,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAQjC,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AAEH,qBAAa,OAAO;IAQT,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,MAAM;IARvB;;;;;OAKG;gBAEM,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM;IAGvB;;;;;OAKG;IAEH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO;IAQ1C;;;;;;;;OAQG;WAEU,UAAU,CACrB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACvC,OAAO,CAAC,OAAO,CAAC;IAmBnB;;;;;;OAMG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/address/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAmB,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAQjC,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AAEH,qBAAa,OAAO;IAQT,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,MAAM;IARvB;;;;;OAKG;gBAEM,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM;IAGvB;;;;;OAKG;IAEH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO;IAQ1C;;;;;;;;OAQG;WAEU,UAAU,CACrB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACvC,OAAO,CAAC,OAAO,CAAC;IAmBnB;;;;;;OAMG;IAEH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;WAIjD,eAAe,CAC1B,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM;IAWhB;;;;OAIG;IAEH,QAAQ,IAAI,MAAM;CAcnB"}
|
package/dist/address/index.js
CHANGED
|
@@ -43,7 +43,7 @@ export class Address {
|
|
|
43
43
|
if (!client) {
|
|
44
44
|
throw new Error(`Unknown address prefix ${prefix}`);
|
|
45
45
|
}
|
|
46
|
-
const expectedPrefix =
|
|
46
|
+
const expectedPrefix = client.addressPrefix;
|
|
47
47
|
if (expectedPrefix !== prefix) {
|
|
48
48
|
throw new Error(`Unknown address prefix ${prefix}, expected ${expectedPrefix}`);
|
|
49
49
|
}
|
|
@@ -56,8 +56,8 @@ export class Address {
|
|
|
56
56
|
* @param client - The client instance used to fetch the address prefix.
|
|
57
57
|
* @returns A promise that resolves to an Address instance.
|
|
58
58
|
*/
|
|
59
|
-
static
|
|
60
|
-
return Address.from({ script, prefix:
|
|
59
|
+
static fromScript(script, client) {
|
|
60
|
+
return Address.from({ script, prefix: client.addressPrefix });
|
|
61
61
|
}
|
|
62
62
|
static async fromKnownScript(script, args, client) {
|
|
63
63
|
return Address.from({
|
|
@@ -65,7 +65,7 @@ export class Address {
|
|
|
65
65
|
...(await client.getKnownScript(script)),
|
|
66
66
|
args,
|
|
67
67
|
},
|
|
68
|
-
prefix:
|
|
68
|
+
prefix: client.addressPrefix,
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
/**
|
package/dist/client/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cell, OutPointLike, Script, ScriptLike, TransactionLike } from "../ckb";
|
|
2
2
|
import { Hex, HexLike } from "../hex";
|
|
3
|
-
import { NumLike } from "../num";
|
|
3
|
+
import { Num, NumLike } from "../num";
|
|
4
4
|
import { ClientFindCellsResponse, ClientIndexerSearchKeyLike, ClientTransactionResponse, OutputsValidator } from "./clientTypes";
|
|
5
5
|
export declare enum KnownScript {
|
|
6
6
|
Secp256k1Blake160 = 0,
|
|
@@ -11,8 +11,8 @@ export declare enum KnownScript {
|
|
|
11
11
|
OmniLock = 5
|
|
12
12
|
}
|
|
13
13
|
export declare abstract class Client {
|
|
14
|
-
abstract
|
|
15
|
-
abstract
|
|
14
|
+
abstract get url(): string;
|
|
15
|
+
abstract get addressPrefix(): string;
|
|
16
16
|
abstract getKnownScript(script: KnownScript): Promise<Pick<Script, "codeHash" | "hashType">>;
|
|
17
17
|
abstract sendTransaction(transaction: TransactionLike, validator?: OutputsValidator): Promise<Hex>;
|
|
18
18
|
abstract getTransaction(txHash: HexLike): Promise<ClientTransactionResponse | null>;
|
|
@@ -20,5 +20,8 @@ export declare abstract class Client {
|
|
|
20
20
|
abstract findCellsPaged(key: ClientIndexerSearchKeyLike, order?: "asc" | "desc", limit?: NumLike, after?: string): Promise<ClientFindCellsResponse>;
|
|
21
21
|
findCells(key: ClientIndexerSearchKeyLike, order?: "asc" | "desc", limit?: number): AsyncGenerator<Cell>;
|
|
22
22
|
findCellsByLockAndType(lock: ScriptLike, type: ScriptLike, withData?: boolean): AsyncGenerator<Cell>;
|
|
23
|
+
abstract getCellsCapacity(key: ClientIndexerSearchKeyLike): Promise<Num>;
|
|
24
|
+
getBalanceSingle(lock: ScriptLike): Promise<Num>;
|
|
25
|
+
getBalance(locks: ScriptLike[]): Promise<Num>;
|
|
23
26
|
}
|
|
24
27
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,UAAU,EACV,eAAe,EAChB,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,UAAU,EACV,eAAe,EAChB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,yBAAyB,EACzB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAEvB,oBAAY,WAAW;IACrB,iBAAiB,IAAA;IACjB,iBAAiB,IAAA;IACjB,YAAY,IAAA;IACZ,KAAK,IAAA;IACL,IAAI,IAAA;IACJ,QAAQ,IAAA;CACT;AAED,8BAAsB,MAAM;IAC1B,QAAQ,KAAK,GAAG,IAAI,MAAM,CAAC;IAC3B,QAAQ,KAAK,aAAa,IAAI,MAAM,CAAC;IAErC,QAAQ,CAAC,cAAc,CACrB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,CAAC;IAEjD,QAAQ,CAAC,eAAe,CACtB,WAAW,EAAE,eAAe,EAC5B,SAAS,CAAC,EAAE,gBAAgB,GAC3B,OAAO,CAAC,GAAG,CAAC;IACf,QAAQ,CAAC,cAAc,CACrB,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAEtC,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAmB3D,QAAQ,CAAC,cAAc,CACrB,GAAG,EAAE,0BAA0B,EAC/B,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,EACtB,KAAK,CAAC,EAAE,OAAO,EACf,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,uBAAuB,CAAC;IAE5B,SAAS,CACd,GAAG,EAAE,0BAA0B,EAC/B,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,EACtB,KAAK,SAAK,GACT,cAAc,CAAC,IAAI,CAAC;IAoBvB,sBAAsB,CACpB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,UAAU,EAChB,QAAQ,UAAO,GACd,cAAc,CAAC,IAAI,CAAC;IAYvB,QAAQ,CAAC,gBAAgB,CAAC,GAAG,EAAE,0BAA0B,GAAG,OAAO,CAAC,GAAG,CAAC;IAElE,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC;IAYhD,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;CAOpD"}
|
package/dist/client/client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Cell, } from "../ckb";
|
|
2
|
+
import { Zero } from "../fixedPoint";
|
|
2
3
|
import { numFrom } from "../num";
|
|
3
4
|
export var KnownScript;
|
|
4
5
|
(function (KnownScript) {
|
|
@@ -50,4 +51,18 @@ export class Client {
|
|
|
50
51
|
withData,
|
|
51
52
|
});
|
|
52
53
|
}
|
|
54
|
+
async getBalanceSingle(lock) {
|
|
55
|
+
return this.getCellsCapacity({
|
|
56
|
+
script: lock,
|
|
57
|
+
scriptType: "lock",
|
|
58
|
+
scriptSearchMode: "exact",
|
|
59
|
+
filter: {
|
|
60
|
+
scriptLenRange: [0, 1],
|
|
61
|
+
outputDataLenRange: [0, 1],
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async getBalance(locks) {
|
|
66
|
+
return locks.reduce((res, lock) => this.getBalanceSingle(lock).then((a) => res.then((b) => a + b)), Promise.resolve(Zero));
|
|
67
|
+
}
|
|
53
68
|
}
|
|
@@ -3,7 +3,7 @@ import { KnownScript } from "./client";
|
|
|
3
3
|
import { ClientJsonRpc } from "./jsonRpc";
|
|
4
4
|
export declare class ClientPublicMainnet extends ClientJsonRpc {
|
|
5
5
|
constructor(url?: string, timeout?: number);
|
|
6
|
-
|
|
6
|
+
get addressPrefix(): string;
|
|
7
7
|
getKnownScript(script: KnownScript): Promise<Pick<Script, "codeHash" | "hashType">>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=clientPublicMainnet.d.ts.map
|
|
@@ -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,GAAG,SAAgC,EAAE,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;IAIjE,IAAI,aAAa,IAAI,MAAM,CAE1B;IAEK,cAAc,CAClB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,CAAC;CAGlD"}
|
|
@@ -3,7 +3,7 @@ import { KnownScript } from "./client";
|
|
|
3
3
|
import { ClientJsonRpc } from "./jsonRpc";
|
|
4
4
|
export declare class ClientPublicTestnet extends ClientJsonRpc {
|
|
5
5
|
constructor(url?: string, timeout?: number);
|
|
6
|
-
|
|
6
|
+
get addressPrefix(): string;
|
|
7
7
|
getKnownScript(script: KnownScript): Promise<Pick<Script, "codeHash" | "hashType">>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=clientPublicTestnet.d.ts.map
|
|
@@ -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,GAAG,SAAgC,EAAE,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;IAIjE,IAAI,aAAa,IAAI,MAAM,CAE1B;IAEK,cAAc,CAClB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,CAAC;CAGlD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TransactionLike } from "../../ckb";
|
|
2
2
|
import { Hex, HexLike } from "../../hex";
|
|
3
|
-
import { NumLike } from "../../num";
|
|
3
|
+
import { Num, NumLike } from "../../num";
|
|
4
4
|
import { Client } from "../client";
|
|
5
5
|
import { ClientFindCellsResponse, ClientIndexerSearchKeyLike, ClientTransactionResponse, OutputsValidator } from "../clientTypes";
|
|
6
6
|
import { JsonRpcPayload } from "./advanced";
|
|
@@ -9,7 +9,7 @@ import { JsonRpcPayload } from "./advanced";
|
|
|
9
9
|
* Provides methods for sending transactions and building JSON-RPC payloads.
|
|
10
10
|
*/
|
|
11
11
|
export declare abstract class ClientJsonRpc extends Client {
|
|
12
|
-
private readonly
|
|
12
|
+
private readonly url_;
|
|
13
13
|
private readonly timeout;
|
|
14
14
|
/**
|
|
15
15
|
* Creates an instance of ClientJsonRpc.
|
|
@@ -17,13 +17,13 @@ export declare abstract class ClientJsonRpc extends Client {
|
|
|
17
17
|
* @param url - The URL of the JSON-RPC server.
|
|
18
18
|
* @param timeout - The timeout for requests in milliseconds, default is 30000.
|
|
19
19
|
*/
|
|
20
|
-
constructor(
|
|
20
|
+
constructor(url_: string, timeout?: number);
|
|
21
21
|
/**
|
|
22
22
|
* Returns the URL of the JSON-RPC server.
|
|
23
23
|
*
|
|
24
24
|
* @returns The URL of the JSON-RPC server.
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
get url(): string;
|
|
27
27
|
/**
|
|
28
28
|
* Send a transaction to node.
|
|
29
29
|
*
|
|
@@ -42,10 +42,20 @@ export declare abstract class ClientJsonRpc extends Client {
|
|
|
42
42
|
/**
|
|
43
43
|
* find cells from node.
|
|
44
44
|
*
|
|
45
|
-
* @param
|
|
45
|
+
* @param key - The search key of cells.
|
|
46
|
+
* @param order - The order of cells.
|
|
47
|
+
* @param limit - The max return size of cells.
|
|
48
|
+
* @param after - Pagination parameter.
|
|
46
49
|
* @returns The found cells.
|
|
47
50
|
*/
|
|
48
51
|
findCellsPaged: (key: ClientIndexerSearchKeyLike, order?: "asc" | "desc", limit?: NumLike, after?: string) => Promise<ClientFindCellsResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* get cells capacity from node.
|
|
54
|
+
*
|
|
55
|
+
* @param key - The search key of cells.
|
|
56
|
+
* @returns The sum of cells capacity.
|
|
57
|
+
*/
|
|
58
|
+
getCellsCapacity: (key: ClientIndexerSearchKeyLike) => Promise<Num>;
|
|
49
59
|
/**
|
|
50
60
|
* Builds a sender function for a JSON-RPC method.
|
|
51
61
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAqB,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,yBAAyB,EACzB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAuB,MAAM,YAAY,CAAC;AA0BjE;;;GAGG;AAEH,8BAAsB,aAAc,SAAQ,MAAM;IAS9C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAT1B;;;;;OAKG;gBAGgB,IAAI,EAAE,MAAM,EACZ,OAAO,SAAQ;IAKlC;;;;OAIG;IAEH,IAAI,GAAG,WAEN;IAED;;;;;;OAMG;IAEH,eAAe,gBAKA,eAAe,cAChB,gBAAgB,GAAG,SAAS,KACrC,QAAQ,GAAG,CAAC,CAAC;IAElB;;;;;OAKG;IAEH,cAAc,WAIA,OAAO,KAAK,QAAQ,yBAAyB,CAAC,CAAC;IAE7D;;;;;;;;OAQG;IAEH,cAAc,QASP,0BAA0B,UACvB,KAAK,GAAG,MAAM,UACd,OAAO,UACP,MAAM,KACX,QAAQ,uBAAuB,CAAC,CAAC;IAEtC;;;;;OAKG;IAEH,gBAAgB,QAIL,0BAA0B,KAAK,QAAQ,GAAG,CAAC,CAAC;IAEvD;;;;;;;OAOG;IAEH,WAAW,CACT,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC,EAAE,EACrD,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,YAEd,OAAO,EAAE;IAkBjC;;;;;;;OAOG;IAEG,IAAI,CAAC,OAAO,EAAE,cAAc;IA4BlC;;;;;;OAMG;IAEH,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,cAAc;CAQpE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fetch from "cross-fetch";
|
|
2
2
|
import { hexFrom } from "../../hex";
|
|
3
|
-
import { numToHex } from "../../num";
|
|
3
|
+
import { numFrom, numToHex } from "../../num";
|
|
4
4
|
import { Client } from "../client";
|
|
5
5
|
import { JsonRpcTransformers } from "./advanced";
|
|
6
6
|
/**
|
|
@@ -33,9 +33,9 @@ export class ClientJsonRpc extends Client {
|
|
|
33
33
|
* @param url - The URL of the JSON-RPC server.
|
|
34
34
|
* @param timeout - The timeout for requests in milliseconds, default is 30000.
|
|
35
35
|
*/
|
|
36
|
-
constructor(
|
|
36
|
+
constructor(url_, timeout = 30000) {
|
|
37
37
|
super();
|
|
38
|
-
this.
|
|
38
|
+
this.url_ = url_;
|
|
39
39
|
this.timeout = timeout;
|
|
40
40
|
/**
|
|
41
41
|
* Send a transaction to node.
|
|
@@ -55,7 +55,10 @@ export class ClientJsonRpc extends Client {
|
|
|
55
55
|
/**
|
|
56
56
|
* find cells from node.
|
|
57
57
|
*
|
|
58
|
-
* @param
|
|
58
|
+
* @param key - The search key of cells.
|
|
59
|
+
* @param order - The order of cells.
|
|
60
|
+
* @param limit - The max return size of cells.
|
|
61
|
+
* @param after - Pagination parameter.
|
|
59
62
|
* @returns The found cells.
|
|
60
63
|
*/
|
|
61
64
|
this.findCellsPaged = this.buildSender("get_cells", [
|
|
@@ -63,14 +66,21 @@ export class ClientJsonRpc extends Client {
|
|
|
63
66
|
(order) => order ?? "asc",
|
|
64
67
|
(limit) => numToHex(limit ?? 10),
|
|
65
68
|
], JsonRpcTransformers.findCellsResponseTo);
|
|
69
|
+
/**
|
|
70
|
+
* get cells capacity from node.
|
|
71
|
+
*
|
|
72
|
+
* @param key - The search key of cells.
|
|
73
|
+
* @returns The sum of cells capacity.
|
|
74
|
+
*/
|
|
75
|
+
this.getCellsCapacity = this.buildSender("get_cells_capacity", [JsonRpcTransformers.indexerSearchKeyFrom], ({ capacity }) => numFrom(capacity));
|
|
66
76
|
}
|
|
67
77
|
/**
|
|
68
78
|
* Returns the URL of the JSON-RPC server.
|
|
69
79
|
*
|
|
70
80
|
* @returns The URL of the JSON-RPC server.
|
|
71
81
|
*/
|
|
72
|
-
|
|
73
|
-
return this.
|
|
82
|
+
get url() {
|
|
83
|
+
return this.url_;
|
|
74
84
|
}
|
|
75
85
|
/**
|
|
76
86
|
* Builds a sender function for a JSON-RPC method.
|
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC"}
|
package/dist/signer/btc/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Address } from "../../address";
|
|
2
2
|
import { Transaction, TransactionLike } from "../../ckb";
|
|
3
3
|
import { HexLike } from "../../hex";
|
|
4
|
-
import { Signer } from "../signer";
|
|
4
|
+
import { Signer, SignerSignType, SignerType } from "../signer";
|
|
5
5
|
/**
|
|
6
6
|
* An abstract class extending the Signer class for Bitcoin-like signing operations.
|
|
7
7
|
* This class provides methods to get Bitcoin account, public key, and internal address,
|
|
8
8
|
* as well as signing transactions.
|
|
9
9
|
*/
|
|
10
10
|
export declare abstract class SignerBtc extends Signer {
|
|
11
|
+
get type(): SignerType;
|
|
12
|
+
get signType(): SignerSignType;
|
|
11
13
|
/**
|
|
12
14
|
* Gets the Bitcoin account associated with the signer.
|
|
13
15
|
*
|
|
@@ -26,6 +28,12 @@ export declare abstract class SignerBtc extends Signer {
|
|
|
26
28
|
* @returns A promise that resolves to a string representing the internal address.
|
|
27
29
|
*/
|
|
28
30
|
getInternalAddress(): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the identity, which is the Bitcoin public key in this case.
|
|
33
|
+
*
|
|
34
|
+
* @returns A promise that resolves to a string representing the identity
|
|
35
|
+
*/
|
|
36
|
+
getIdentity(): Promise<string>;
|
|
29
37
|
/**
|
|
30
38
|
* Gets an array of Address objects representing the known script addresses for the signer.
|
|
31
39
|
*
|
|
@@ -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;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;
|
|
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;AAE7C,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/D;;;;GAIG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C,IAAI,IAAI,IAAI,UAAU,CAErB;IAED,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED;;;;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,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAIpC;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAa1C;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IASvE;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAgCzE"}
|
|
@@ -6,13 +6,19 @@ 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 { Signer } from "../signer";
|
|
9
|
+
import { Signer, SignerSignType, SignerType } from "../signer";
|
|
10
10
|
/**
|
|
11
11
|
* An abstract class extending the Signer class for Bitcoin-like signing operations.
|
|
12
12
|
* This class provides methods to get Bitcoin account, public key, and internal address,
|
|
13
13
|
* as well as signing transactions.
|
|
14
14
|
*/
|
|
15
15
|
export class SignerBtc extends Signer {
|
|
16
|
+
get type() {
|
|
17
|
+
return SignerType.BTC;
|
|
18
|
+
}
|
|
19
|
+
get signType() {
|
|
20
|
+
return SignerSignType.BtcEcdsa;
|
|
21
|
+
}
|
|
16
22
|
/**
|
|
17
23
|
* Gets the internal address, which is the Bitcoin account in this case.
|
|
18
24
|
*
|
|
@@ -21,6 +27,14 @@ export class SignerBtc extends Signer {
|
|
|
21
27
|
async getInternalAddress() {
|
|
22
28
|
return this.getBtcAccount();
|
|
23
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets the identity, which is the Bitcoin public key in this case.
|
|
32
|
+
*
|
|
33
|
+
* @returns A promise that resolves to a string representing the identity
|
|
34
|
+
*/
|
|
35
|
+
async getIdentity() {
|
|
36
|
+
return hexFrom(await this.getBtcPublicKey()).slice(2);
|
|
37
|
+
}
|
|
24
38
|
/**
|
|
25
39
|
* Gets an array of Address objects representing the known script addresses for the signer.
|
|
26
40
|
*
|
|
@@ -56,7 +70,7 @@ export class SignerBtc extends Signer {
|
|
|
56
70
|
if (!info) {
|
|
57
71
|
return tx;
|
|
58
72
|
}
|
|
59
|
-
const signature = bytesFrom(await this.
|
|
73
|
+
const signature = bytesFrom(await this.signMessageRaw(`CKB (Bitcoin Layer) transaction: ${info.message}`), "base64");
|
|
60
74
|
signature[0] = 31 + ((signature[0] - 27) % 4);
|
|
61
75
|
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
62
76
|
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));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/verify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAKT"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { verifyMessage } from "@unisat/wallet-utils";
|
|
2
|
+
import { hexFrom } from "../../hex";
|
|
3
|
+
export function verifyMessageBtcEcdsa(message, signature, publicKey) {
|
|
4
|
+
const challenge = typeof message === "string" ? message : hexFrom(message).slice(2);
|
|
5
|
+
return verifyMessage(publicKey, challenge, signature);
|
|
6
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC"}
|
package/dist/signer/ckb/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Address } from "../../address";
|
|
2
2
|
import { ScriptLike } from "../../ckb";
|
|
3
3
|
import { Client } from "../../client";
|
|
4
|
-
import { Signer } from "../signer";
|
|
4
|
+
import { Signer, SignerSignType, SignerType } from "../signer";
|
|
5
5
|
/**
|
|
6
6
|
* A class extending Signer that provides read-only access to a CKB script.
|
|
7
7
|
* This class does not support signing operations.
|
|
8
8
|
*/
|
|
9
9
|
export declare class SignerCkbScriptReadonly extends Signer {
|
|
10
|
+
get type(): SignerType;
|
|
11
|
+
get signType(): SignerSignType;
|
|
10
12
|
private readonly script;
|
|
11
13
|
/**
|
|
12
14
|
* Creates an instance of SignerCkbScriptReadonly.
|
|
@@ -1 +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;
|
|
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,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/D;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,MAAM;IACjD,IAAI,IAAI,IAAI,UAAU,CAErB;IAED,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAM9C;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAIrE;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;OASG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;;;;;;OASG;IAEG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG3C"}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { Address } from "../../address";
|
|
2
2
|
import { Script } from "../../ckb";
|
|
3
|
-
import { Signer } from "../signer";
|
|
3
|
+
import { Signer, SignerSignType, SignerType } from "../signer";
|
|
4
4
|
/**
|
|
5
5
|
* A class extending Signer that provides read-only access to a CKB script.
|
|
6
6
|
* This class does not support signing operations.
|
|
7
7
|
*/
|
|
8
8
|
export class SignerCkbScriptReadonly extends Signer {
|
|
9
|
+
get type() {
|
|
10
|
+
return SignerType.CKB;
|
|
11
|
+
}
|
|
12
|
+
get signType() {
|
|
13
|
+
return SignerSignType.Unknown;
|
|
14
|
+
}
|
|
9
15
|
/**
|
|
10
16
|
* Creates an instance of SignerCkbScriptReadonly.
|
|
11
17
|
*
|
|
@@ -62,6 +68,6 @@ export class SignerCkbScriptReadonly extends Signer {
|
|
|
62
68
|
* ```
|
|
63
69
|
*/
|
|
64
70
|
async getAddressObjs() {
|
|
65
|
-
return [
|
|
71
|
+
return [Address.fromScript(this.script, this.client)];
|
|
66
72
|
}
|
|
67
73
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifyJoyId.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/verifyJoyId.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC,CAWlB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { verifySignature } from "@joyid/ckb";
|
|
2
|
+
import { hexFrom } from "../../hex";
|
|
3
|
+
export function verifyMessageJoyId(message, signature, identity) {
|
|
4
|
+
const challenge = typeof message === "string" ? message : hexFrom(message).slice(2);
|
|
5
|
+
const { publicKey, keyType } = JSON.parse(identity);
|
|
6
|
+
return verifySignature({
|
|
7
|
+
challenge,
|
|
8
|
+
pubkey: publicKey,
|
|
9
|
+
keyType,
|
|
10
|
+
...JSON.parse(signature),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,UAAU,CAAC"}
|
package/dist/signer/evm/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Address } from "../../address";
|
|
2
2
|
import { BytesLike } from "../../bytes";
|
|
3
3
|
import { Script, Transaction, TransactionLike } from "../../ckb";
|
|
4
|
-
import { Signer } from "../signer";
|
|
4
|
+
import { Signer, SignerSignType, SignerType } from "../signer";
|
|
5
5
|
/**
|
|
6
6
|
* An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
|
|
7
7
|
* This class provides methods to get EVM account, internal address, and signing transactions.
|
|
8
8
|
*/
|
|
9
9
|
export declare abstract class SignerEvm extends Signer {
|
|
10
|
+
get type(): SignerType;
|
|
11
|
+
get signType(): SignerSignType;
|
|
10
12
|
/**
|
|
11
13
|
* Gets the EVM account associated with the signer.
|
|
12
14
|
*
|
|
@@ -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;AACxC,OAAO,EAAE,SAAS,EAA0B,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAI9E,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"signerEvm.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAA0B,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAI9E,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/D;;;GAGG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C,IAAI,IAAI,IAAI,UAAU,CAErB;IAED,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED;;;;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;IAQpC,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ5D,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQrE;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAYvE;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAsBlE,iCAAiC,CACrC,EAAE,EAAE,WAAW,EACf,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAC9C,OAAO,CAAC,WAAW,CAAC;CA6BxB"}
|
|
@@ -4,12 +4,18 @@ 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 { Signer } from "../signer";
|
|
7
|
+
import { Signer, SignerSignType, SignerType } from "../signer";
|
|
8
8
|
/**
|
|
9
9
|
* An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
|
|
10
10
|
* This class provides methods to get EVM account, internal address, and signing transactions.
|
|
11
11
|
*/
|
|
12
12
|
export class SignerEvm extends Signer {
|
|
13
|
+
get type() {
|
|
14
|
+
return SignerType.EVM;
|
|
15
|
+
}
|
|
16
|
+
get signType() {
|
|
17
|
+
return SignerSignType.EvmPersonal;
|
|
18
|
+
}
|
|
13
19
|
/**
|
|
14
20
|
* Gets the internal address, which is the EVM account in this case.
|
|
15
21
|
*
|
|
@@ -66,7 +72,7 @@ export class SignerEvm extends Signer {
|
|
|
66
72
|
if (!info) {
|
|
67
73
|
return tx;
|
|
68
74
|
}
|
|
69
|
-
const signature = bytesFrom(await this.
|
|
75
|
+
const signature = bytesFrom(await this.signMessageRaw(messageTransformer(info.message)));
|
|
70
76
|
if (signature[signature.length - 1] >= 27) {
|
|
71
77
|
signature[signature.length - 1] -= 27;
|
|
72
78
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/verify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAa,MAAM,aAAa,CAAC;AAEnD,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAQT"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { verifyMessage } from "ethers";
|
|
2
|
+
import { bytesFrom } from "../../bytes";
|
|
3
|
+
export function verifyMessageEvmPersonal(message, signature, address) {
|
|
4
|
+
return (address.toLowerCase() ===
|
|
5
|
+
verifyMessage(typeof message === "string" ? message : bytesFrom(message), signature).toLowerCase());
|
|
6
|
+
}
|