@ckb-ccc/core 0.0.5-alpha.0 → 0.0.5-alpha.10
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/ckb/transaction.d.ts +2 -2
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +2 -3
- package/dist/client/client.d.ts +6 -3
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +16 -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 +19 -3
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +0 -6
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
- package/dist/signer/btc/signerBtcPublicKeyReadonly.js +0 -8
- 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 -7
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist/signer/ckb/signerCkbScriptReadonly.js +8 -10
- 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/dummy/alwaysError.d.ts +9 -0
- package/dist/signer/dummy/alwaysError.d.ts.map +1 -0
- package/dist/signer/dummy/alwaysError.js +10 -0
- package/dist/signer/dummy/dummy.d.ts +12 -0
- package/dist/signer/dummy/dummy.d.ts.map +1 -0
- package/dist/signer/dummy/dummy.js +19 -0
- package/dist/signer/dummy/index.d.ts +4 -0
- package/dist/signer/dummy/index.d.ts.map +1 -0
- package/dist/signer/dummy/index.js +3 -0
- package/dist/signer/dummy/openLink.d.ts +9 -0
- package/dist/signer/dummy/openLink.d.ts.map +1 -0
- package/dist/signer/dummy/openLink.js +10 -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 +10 -4
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts +0 -6
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
- package/dist/signer/evm/signerEvmAddressReadonly.js +0 -8
- 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/index.d.ts +1 -0
- package/dist/signer/index.d.ts.map +1 -1
- package/dist/signer/index.js +1 -0
- package/{dist.commonjs/signer/signer.d.ts → dist/signer/signer/index.d.ts} +75 -24
- package/dist/signer/signer/index.d.ts.map +1 -0
- package/dist/signer/signer/index.js +205 -0
- package/dist/utils/index.d.ts +60 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +20 -0
- package/dist.commonjs/address/address.advanced.d.ts +29 -24
- package/dist.commonjs/address/address.advanced.js +114 -92
- package/dist.commonjs/address/advanced.d.ts +1 -1
- package/dist.commonjs/address/advanced.js +30 -14
- package/dist.commonjs/address/index.d.ts +51 -44
- package/dist.commonjs/address/index.d.ts.map +1 -1
- package/dist.commonjs/address/index.js +87 -68
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +47 -22
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +30 -14
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +30 -14
- package/dist.commonjs/bytes/advanced.d.ts +11 -2
- package/dist.commonjs/bytes/index.d.ts +9 -3
- package/dist.commonjs/bytes/index.js +28 -26
- package/dist.commonjs/ckb/advanced.d.ts +1 -1
- package/dist.commonjs/ckb/advanced.js +47 -22
- package/dist.commonjs/ckb/index.d.ts +1 -1
- package/dist.commonjs/ckb/index.js +30 -14
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
- package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
- package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
- package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/script.advanced.js +12 -9
- package/dist.commonjs/ckb/script.d.ts +76 -76
- package/dist.commonjs/ckb/script.js +166 -126
- package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/transaction.advanced.js +4 -4
- package/dist.commonjs/ckb/transaction.d.ts +570 -532
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +839 -723
- package/dist.commonjs/client/advanced.d.ts +1 -1
- package/dist.commonjs/client/advanced.js +30 -14
- package/dist.commonjs/client/client.d.ts +53 -19
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +68 -43
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +5 -2
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +30 -24
- package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -4
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.js +9 -9
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +5 -2
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +30 -24
- package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -4
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.js +9 -9
- package/dist.commonjs/client/clientTypes.d.ts +51 -36
- package/dist.commonjs/client/clientTypes.js +34 -19
- package/dist.commonjs/client/index.d.ts +1 -1
- package/dist.commonjs/client/index.js +30 -14
- package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
- package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
- package/dist.commonjs/client/jsonRpc/index.d.ts +93 -66
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +135 -98
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +78 -38
- package/dist.commonjs/client/jsonRpc/transformers.js +175 -150
- package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
- package/dist.commonjs/fixedPoint/index.d.ts +9 -3
- package/dist.commonjs/fixedPoint/index.js +26 -20
- package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
- package/dist.commonjs/fixedPoint/index.test.js +42 -36
- package/dist.commonjs/hasher/advanced.d.ts +1 -1
- package/dist.commonjs/hasher/index.d.ts +36 -36
- package/dist.commonjs/hasher/index.js +52 -45
- package/dist.commonjs/hex/index.d.ts +1 -1
- package/dist.commonjs/hex/index.js +1 -1
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +47 -22
- package/dist.commonjs/num/index.d.ts +1 -1
- package/dist.commonjs/num/index.js +30 -19
- package/dist.commonjs/signer/btc/index.d.ts +2 -1
- package/dist.commonjs/signer/btc/index.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/index.js +31 -14
- package/dist.commonjs/signer/btc/signerBtc.d.ts +48 -40
- package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/signerBtc.js +85 -49
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -51
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -60
- package/dist.commonjs/signer/btc/verify.d.ts +7 -0
- package/dist.commonjs/signer/btc/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/verify.js +13 -0
- package/dist.commonjs/signer/ckb/index.d.ts +2 -1
- package/dist.commonjs/signer/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/index.js +31 -14
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +46 -50
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -58
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +7 -0
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/verifyJoyId.js +19 -0
- package/dist.commonjs/signer/dummy/alwaysError.d.ts +9 -0
- package/dist.commonjs/signer/dummy/alwaysError.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/alwaysError.js +14 -0
- package/dist.commonjs/signer/dummy/dummy.d.ts +12 -0
- package/dist.commonjs/signer/dummy/dummy.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/dummy.js +23 -0
- package/dist.commonjs/signer/dummy/index.d.ts +4 -0
- package/dist.commonjs/signer/dummy/index.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/index.js +35 -0
- package/dist.commonjs/signer/dummy/openLink.d.ts +9 -0
- package/dist.commonjs/signer/dummy/openLink.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/openLink.js +14 -0
- package/dist.commonjs/signer/evm/index.d.ts +2 -1
- package/dist.commonjs/signer/evm/index.d.ts.map +1 -1
- package/dist.commonjs/signer/evm/index.js +31 -14
- package/dist.commonjs/signer/evm/signerEvm.d.ts +43 -37
- package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist.commonjs/signer/evm/signerEvm.js +101 -63
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -43
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -50
- package/dist.commonjs/signer/evm/verify.d.ts +7 -0
- package/dist.commonjs/signer/evm/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/verify.js +15 -0
- package/dist.commonjs/signer/index.d.ts +2 -1
- package/dist.commonjs/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/index.js +31 -14
- package/dist.commonjs/signer/signer/index.d.ts +190 -0
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -0
- package/dist.commonjs/signer/signer/index.js +234 -0
- package/dist.commonjs/utils/index.d.ts +94 -6
- package/dist.commonjs/utils/index.d.ts.map +1 -1
- package/dist.commonjs/utils/index.js +33 -5
- package/package.json +6 -3
- package/src/address/index.ts +4 -7
- package/src/ckb/transaction.ts +4 -5
- package/src/client/client.ts +27 -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 +22 -7
- package/src/signer/btc/signerBtcPublicKeyReadonly.ts +0 -9
- package/src/signer/btc/verify.ts +14 -0
- package/src/signer/ckb/index.ts +1 -0
- package/src/signer/ckb/signerCkbScriptReadonly.ts +10 -11
- package/src/signer/ckb/verifyJoyId.ts +20 -0
- package/src/signer/dummy/alwaysError.ts +17 -0
- package/src/signer/dummy/dummy.ts +28 -0
- package/src/signer/dummy/index.ts +3 -0
- package/src/signer/dummy/openLink.ts +17 -0
- package/src/signer/evm/index.ts +1 -0
- package/src/signer/evm/signerEvm.ts +16 -10
- package/src/signer/evm/signerEvmAddressReadonly.ts +0 -9
- package/src/signer/evm/verify.ts +16 -0
- package/src/signer/index.ts +1 -0
- package/src/signer/{signer.ts → signer/index.ts} +146 -24
- package/src/utils/index.ts +108 -0
- package/dist/signer/signer.d.ts +0 -133
- package/dist/signer/signer.d.ts.map +0 -1
- package/dist/signer/signer.js +0 -112
- package/dist.commonjs/signer/signer.d.ts.map +0 -1
- package/dist.commonjs/signer/signer.js +0 -117
- package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +0 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Client } from "../../client";
|
|
2
|
+
import { SignerType } from "../signer";
|
|
3
|
+
import { SignerDummy } from "./dummy";
|
|
4
|
+
export declare class SignerAlwaysError extends SignerDummy {
|
|
5
|
+
private readonly message;
|
|
6
|
+
constructor(client: Client, type: SignerType, message: string);
|
|
7
|
+
connect(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=alwaysError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alwaysError.d.ts","sourceRoot":"","sources":["../../../src/signer/dummy/alwaysError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,iBAAkB,SAAQ,WAAW;IAI9C,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAFxB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,UAAU,EACC,OAAO,EAAE,MAAM;IAK5B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Address } from "../../address";
|
|
2
|
+
import { Client } from "../../client";
|
|
3
|
+
import { Signer, SignerSignType, SignerType } from "../signer";
|
|
4
|
+
export declare abstract class SignerDummy extends Signer {
|
|
5
|
+
readonly type: SignerType;
|
|
6
|
+
get signType(): SignerSignType;
|
|
7
|
+
constructor(client: Client, type: SignerType);
|
|
8
|
+
isConnected(): Promise<boolean>;
|
|
9
|
+
getInternalAddress(): Promise<string>;
|
|
10
|
+
getAddressObjs(): Promise<Address[]>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=dummy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dummy.d.ts","sourceRoot":"","sources":["../../../src/signer/dummy/dummy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/D,8BAAsB,WAAY,SAAQ,MAAM;aAO5B,IAAI,EAAE,UAAU;IANlC,IAAI,QAAQ,IAAI,cAAc,CAE7B;gBAGC,MAAM,EAAE,MAAM,EACE,IAAI,EAAE,UAAU;IAK5B,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG3C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Signer, SignerSignType } from "../signer";
|
|
2
|
+
export class SignerDummy extends Signer {
|
|
3
|
+
get signType() {
|
|
4
|
+
return SignerSignType.Unknown;
|
|
5
|
+
}
|
|
6
|
+
constructor(client, type) {
|
|
7
|
+
super(client);
|
|
8
|
+
this.type = type;
|
|
9
|
+
}
|
|
10
|
+
async isConnected() {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
async getInternalAddress() {
|
|
14
|
+
throw new Error("Can't get address from SignerDummy");
|
|
15
|
+
}
|
|
16
|
+
async getAddressObjs() {
|
|
17
|
+
throw new Error("Can't get addresses from SignerDummy");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/dummy/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Client } from "../../client";
|
|
2
|
+
import { SignerType } from "../signer";
|
|
3
|
+
import { SignerDummy } from "./dummy";
|
|
4
|
+
export declare class SignerOpenLink extends SignerDummy {
|
|
5
|
+
private readonly link;
|
|
6
|
+
constructor(client: Client, type: SignerType, link: string);
|
|
7
|
+
connect(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=openLink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openLink.d.ts","sourceRoot":"","sources":["../../../src/signer/dummy/openLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,cAAe,SAAQ,WAAW;IAI3C,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAFrB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,UAAU,EACC,IAAI,EAAE,MAAM;IAKzB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
|
|
@@ -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,O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AC9C,OAAO,CAAC,WAAW,CAAC;CA6BxB"}
|
|
@@ -4,12 +4,19 @@ 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 {
|
|
7
|
+
import { reduceAsync } from "../../utils";
|
|
8
|
+
import { Signer, SignerSignType, SignerType } from "../signer";
|
|
8
9
|
/**
|
|
9
10
|
* An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
|
|
10
11
|
* This class provides methods to get EVM account, internal address, and signing transactions.
|
|
11
12
|
*/
|
|
12
13
|
export class SignerEvm extends Signer {
|
|
14
|
+
get type() {
|
|
15
|
+
return SignerType.EVM;
|
|
16
|
+
}
|
|
17
|
+
get signType() {
|
|
18
|
+
return SignerSignType.EvmPersonal;
|
|
19
|
+
}
|
|
13
20
|
/**
|
|
14
21
|
* Gets the internal address, which is the EVM account in this case.
|
|
15
22
|
*
|
|
@@ -43,8 +50,7 @@ export class SignerEvm extends Signer {
|
|
|
43
50
|
* @returns A promise that resolves to the prepared Transaction object.
|
|
44
51
|
*/
|
|
45
52
|
async prepareTransaction(txLike) {
|
|
46
|
-
|
|
47
|
-
return addresses.reduce((txPromise, { script }) => txPromise.then((tx) => tx.prepareSighashAllWitness(script, 85, this.client)), Promise.resolve(Transaction.from(txLike)));
|
|
53
|
+
return reduceAsync(await this.getAddressObjs(), (tx, { script }) => tx.prepareSighashAllWitness(script, 85, this.client), Transaction.from(txLike));
|
|
48
54
|
}
|
|
49
55
|
/**
|
|
50
56
|
* Signs a transaction without modifying it.
|
|
@@ -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
|
}
|
|
@@ -14,12 +14,6 @@ export declare class SignerEvmAddressReadonly extends SignerEvm {
|
|
|
14
14
|
* @param address - The EVM address associated with the signer.
|
|
15
15
|
*/
|
|
16
16
|
constructor(client: Client, address: HexLike);
|
|
17
|
-
/**
|
|
18
|
-
* Construct a new signer with the client replaced.
|
|
19
|
-
*
|
|
20
|
-
* @returns A promise that resolves the new Signer.
|
|
21
|
-
*/
|
|
22
|
-
replaceClient(client: Client): Promise<SignerEvmAddressReadonly>;
|
|
23
17
|
/**
|
|
24
18
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
25
19
|
*
|
|
@@ -1 +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;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;IAE9B;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAM5C
|
|
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;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;IAE9B;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAM5C;;;;;;;;;OASG;IAEG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;OASG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAGvC"}
|
|
@@ -15,14 +15,6 @@ export class SignerEvmAddressReadonly extends SignerEvm {
|
|
|
15
15
|
super(client);
|
|
16
16
|
this.address = hexFrom(address);
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Construct a new signer with the client replaced.
|
|
20
|
-
*
|
|
21
|
-
* @returns A promise that resolves the new Signer.
|
|
22
|
-
*/
|
|
23
|
-
async replaceClient(client) {
|
|
24
|
-
return new SignerEvmAddressReadonly(client, this.address);
|
|
25
|
-
}
|
|
26
18
|
/**
|
|
27
19
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
28
20
|
*
|
|
@@ -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
|
+
}
|
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,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,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,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC"}
|
package/dist/signer/index.js
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
import { Address } from "
|
|
2
|
-
import { BytesLike } from "
|
|
3
|
-
import { Transaction, TransactionLike } from "
|
|
4
|
-
import { Client } from "
|
|
5
|
-
import { Hex } from "
|
|
1
|
+
import { Address } from "../../address";
|
|
2
|
+
import { BytesLike } from "../../bytes";
|
|
3
|
+
import { Transaction, TransactionLike } from "../../ckb";
|
|
4
|
+
import { Client } from "../../client";
|
|
5
|
+
import { Hex } from "../../hex";
|
|
6
|
+
import { Num } from "../../num";
|
|
7
|
+
export declare enum SignerSignType {
|
|
8
|
+
Unknown = "Unknown",
|
|
9
|
+
BtcEcdsa = "BtcEcdsa",
|
|
10
|
+
EvmPersonal = "EvmPersonal",
|
|
11
|
+
JoyId = "JoyId"
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* An enumeration of signer display types in wallet.
|
|
15
|
+
*/
|
|
16
|
+
export declare enum SignerType {
|
|
17
|
+
EVM = "EVM",
|
|
18
|
+
BTC = "BTC",
|
|
19
|
+
CKB = "CKB"
|
|
20
|
+
}
|
|
21
|
+
export declare class Signature {
|
|
22
|
+
signature: string;
|
|
23
|
+
identity: string;
|
|
24
|
+
signType: SignerSignType;
|
|
25
|
+
constructor(signature: string, identity: string, signType: SignerSignType);
|
|
26
|
+
}
|
|
6
27
|
/**
|
|
7
28
|
* An abstract class representing a generic signer.
|
|
8
29
|
* This class provides methods to connect, get addresses, and sign transactions.
|
|
@@ -10,13 +31,14 @@ import { Hex } from "../hex";
|
|
|
10
31
|
export declare abstract class Signer {
|
|
11
32
|
protected client_: Client;
|
|
12
33
|
constructor(client_: Client);
|
|
34
|
+
abstract get type(): SignerType;
|
|
35
|
+
abstract get signType(): SignerSignType;
|
|
13
36
|
get client(): Client;
|
|
37
|
+
static verifyMessage(message: string | BytesLike, signature: Signature): Promise<boolean>;
|
|
14
38
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @returns A promise that resolves the new Signer.
|
|
39
|
+
* Replace the current client.
|
|
18
40
|
*/
|
|
19
|
-
|
|
41
|
+
replaceClient(client: Client): Promise<void>;
|
|
20
42
|
/**
|
|
21
43
|
* Connects to the signer.
|
|
22
44
|
*
|
|
@@ -41,6 +63,12 @@ export declare abstract class Signer {
|
|
|
41
63
|
* @returns A promise that resolves to a string representing the internal address.
|
|
42
64
|
*/
|
|
43
65
|
abstract getInternalAddress(): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Gets the identity for verifying signature, usually it's address
|
|
68
|
+
*
|
|
69
|
+
* @returns A promise that resolves to a string representing the identity
|
|
70
|
+
*/
|
|
71
|
+
getIdentity(): Promise<string>;
|
|
44
72
|
/**
|
|
45
73
|
* Gets an array of Address objects associated with the signer.
|
|
46
74
|
*
|
|
@@ -68,13 +96,45 @@ export declare abstract class Signer {
|
|
|
68
96
|
*/
|
|
69
97
|
getAddresses(): Promise<string[]>;
|
|
70
98
|
/**
|
|
71
|
-
*
|
|
99
|
+
* Gets balance of all addresses
|
|
100
|
+
*
|
|
101
|
+
* @returns A promise that resolves to the balance
|
|
102
|
+
*/
|
|
103
|
+
getBalance(): Promise<Num>;
|
|
104
|
+
/**
|
|
105
|
+
* Signs a message.
|
|
106
|
+
*
|
|
107
|
+
* @param _ - The message to sign, as a string or BytesLike object.
|
|
108
|
+
* @returns A promise that resolves to the signature info.
|
|
109
|
+
* @throws Will throw an error if not implemented.
|
|
110
|
+
*/
|
|
111
|
+
signMessage(message: string | BytesLike): Promise<Signature>;
|
|
112
|
+
/**
|
|
113
|
+
* Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
|
|
72
114
|
*
|
|
73
115
|
* @param _ - The message to sign, as a string or BytesLike object.
|
|
74
|
-
* @returns A promise that resolves to the
|
|
116
|
+
* @returns A promise that resolves to the signature as a string.
|
|
117
|
+
* @throws Will throw an error if not implemented.
|
|
118
|
+
*/
|
|
119
|
+
signMessageRaw(_: string | BytesLike): Promise<string>;
|
|
120
|
+
/**
|
|
121
|
+
* Verify a signature.
|
|
122
|
+
*
|
|
123
|
+
* @param _ - The original message.
|
|
124
|
+
* @param _ - The signature to verify.
|
|
125
|
+
* @returns A promise that resolves to the verification result.
|
|
126
|
+
* @throws Will throw an error if not implemented.
|
|
127
|
+
*/
|
|
128
|
+
verifyMessage(message: string | BytesLike, signature: string | Signature): Promise<boolean>;
|
|
129
|
+
/**
|
|
130
|
+
* Verify a string signature. This method is not implemented and should be overridden by subclasses.
|
|
131
|
+
*
|
|
132
|
+
* @param _0 - The original message.
|
|
133
|
+
* @param _1 - The signature to verify.
|
|
134
|
+
* @returns A promise that resolves to the verification result.
|
|
75
135
|
* @throws Will throw an error if not implemented.
|
|
76
136
|
*/
|
|
77
|
-
|
|
137
|
+
verifyMessageRaw(_0: string | BytesLike, _1: string): Promise<boolean>;
|
|
78
138
|
/**
|
|
79
139
|
* Sends a transaction after signing it.
|
|
80
140
|
*
|
|
@@ -98,7 +158,7 @@ export declare abstract class Signer {
|
|
|
98
158
|
*/
|
|
99
159
|
prepareTransaction(_: TransactionLike): Promise<Transaction>;
|
|
100
160
|
/**
|
|
101
|
-
* Signs a transaction without
|
|
161
|
+
* Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
|
|
102
162
|
*
|
|
103
163
|
* @param _ - The transaction to sign, represented as a TransactionLike object.
|
|
104
164
|
* @returns A promise that resolves to the signed Transaction object.
|
|
@@ -106,22 +166,13 @@ export declare abstract class Signer {
|
|
|
106
166
|
*/
|
|
107
167
|
signOnlyTransaction(_: TransactionLike): Promise<Transaction>;
|
|
108
168
|
}
|
|
109
|
-
/**
|
|
110
|
-
* An enumeration of signer types.
|
|
111
|
-
*/
|
|
112
|
-
export declare enum SignerType {
|
|
113
|
-
EVM = "EVM",
|
|
114
|
-
BTC = "BTC",
|
|
115
|
-
CKB = "CKB"
|
|
116
|
-
}
|
|
117
169
|
/**
|
|
118
170
|
* A class representing information about a signer, including its type and the signer instance.
|
|
119
171
|
*/
|
|
120
172
|
export declare class SignerInfo {
|
|
121
173
|
name: string;
|
|
122
|
-
type: SignerType;
|
|
123
174
|
signer: Signer;
|
|
124
|
-
constructor(name: string,
|
|
175
|
+
constructor(name: string, signer: Signer);
|
|
125
176
|
}
|
|
126
177
|
/**
|
|
127
178
|
* Represents a wallet with a name, icon, and an array of signer information.
|
|
@@ -130,4 +181,4 @@ export type Wallet = {
|
|
|
130
181
|
name: string;
|
|
131
182
|
icon: string;
|
|
132
183
|
};
|
|
133
|
-
//# sourceMappingURL=
|
|
184
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/signer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAKhC,oBAAY,cAAc;IACxB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,KAAK,UAAU;CAChB;AAED;;GAEG;AAC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a } from "../btc";
|
|
2
|
+
import { verifyMessageJoyId } from "../ckb/verifyJoyId";
|
|
3
|
+
import { verifyMessageEvmPersonal } from "../evm/verify";
|
|
4
|
+
export var SignerSignType;
|
|
5
|
+
(function (SignerSignType) {
|
|
6
|
+
SignerSignType["Unknown"] = "Unknown";
|
|
7
|
+
SignerSignType["BtcEcdsa"] = "BtcEcdsa";
|
|
8
|
+
SignerSignType["EvmPersonal"] = "EvmPersonal";
|
|
9
|
+
SignerSignType["JoyId"] = "JoyId";
|
|
10
|
+
})(SignerSignType || (SignerSignType = {}));
|
|
11
|
+
/**
|
|
12
|
+
* An enumeration of signer display types in wallet.
|
|
13
|
+
*/
|
|
14
|
+
export var SignerType;
|
|
15
|
+
(function (SignerType) {
|
|
16
|
+
SignerType["EVM"] = "EVM";
|
|
17
|
+
SignerType["BTC"] = "BTC";
|
|
18
|
+
SignerType["CKB"] = "CKB";
|
|
19
|
+
})(SignerType || (SignerType = {}));
|
|
20
|
+
export class Signature {
|
|
21
|
+
constructor(signature, identity, signType) {
|
|
22
|
+
this.signature = signature;
|
|
23
|
+
this.identity = identity;
|
|
24
|
+
this.signType = signType;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* An abstract class representing a generic signer.
|
|
29
|
+
* This class provides methods to connect, get addresses, and sign transactions.
|
|
30
|
+
*/
|
|
31
|
+
export class Signer {
|
|
32
|
+
constructor(client_) {
|
|
33
|
+
this.client_ = client_;
|
|
34
|
+
}
|
|
35
|
+
get client() {
|
|
36
|
+
return this.client_;
|
|
37
|
+
}
|
|
38
|
+
static async verifyMessage(message, signature) {
|
|
39
|
+
switch (signature.signType) {
|
|
40
|
+
case SignerSignType.EvmPersonal:
|
|
41
|
+
return verifyMessageEvmPersonal(message, signature.signature, signature.identity);
|
|
42
|
+
case SignerSignType.BtcEcdsa:
|
|
43
|
+
return verifyMessageBtcEcdsa(message, signature.signature, signature.identity);
|
|
44
|
+
case SignerSignType.JoyId:
|
|
45
|
+
return verifyMessageJoyId(message, signature.signature, signature.identity);
|
|
46
|
+
case SignerSignType.Unknown:
|
|
47
|
+
throw new Error("Unknown signer sign type");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Replace the current client.
|
|
52
|
+
*/
|
|
53
|
+
async replaceClient(client) {
|
|
54
|
+
this.client_ = client;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Disconnects to the signer.
|
|
58
|
+
*
|
|
59
|
+
* @returns A promise that resolves when disconnected.
|
|
60
|
+
*/
|
|
61
|
+
async disconnect() { }
|
|
62
|
+
/**
|
|
63
|
+
* Gets the identity for verifying signature, usually it's address
|
|
64
|
+
*
|
|
65
|
+
* @returns A promise that resolves to a string representing the identity
|
|
66
|
+
*/
|
|
67
|
+
async getIdentity() {
|
|
68
|
+
return this.getInternalAddress();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Gets the recommended Address object for the signer.
|
|
72
|
+
*
|
|
73
|
+
* @param _preference - Optional preference parameter.
|
|
74
|
+
* @returns A promise that resolves to the recommended Address object.
|
|
75
|
+
*/
|
|
76
|
+
async getRecommendedAddressObj(_preference) {
|
|
77
|
+
return (await this.getAddressObjs())[0];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Gets the recommended address for the signer as a string.
|
|
81
|
+
*
|
|
82
|
+
* @param preference - Optional preference parameter.
|
|
83
|
+
* @returns A promise that resolves to the recommended address as a string.
|
|
84
|
+
*/
|
|
85
|
+
async getRecommendedAddress(preference) {
|
|
86
|
+
return (await this.getRecommendedAddressObj(preference)).toString();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Gets an array of addresses associated with the signer as strings.
|
|
90
|
+
*
|
|
91
|
+
* @returns A promise that resolves to an array of addresses as strings.
|
|
92
|
+
*/
|
|
93
|
+
async getAddresses() {
|
|
94
|
+
return this.getAddressObjs().then((addresses) => addresses.map((address) => address.toString()));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Gets balance of all addresses
|
|
98
|
+
*
|
|
99
|
+
* @returns A promise that resolves to the balance
|
|
100
|
+
*/
|
|
101
|
+
async getBalance() {
|
|
102
|
+
return this.client.getBalance((await this.getAddressObjs()).map(({ script }) => script));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Signs a message.
|
|
106
|
+
*
|
|
107
|
+
* @param _ - The message to sign, as a string or BytesLike object.
|
|
108
|
+
* @returns A promise that resolves to the signature info.
|
|
109
|
+
* @throws Will throw an error if not implemented.
|
|
110
|
+
*/
|
|
111
|
+
async signMessage(message) {
|
|
112
|
+
return {
|
|
113
|
+
signature: await this.signMessageRaw(message),
|
|
114
|
+
identity: await this.getIdentity(),
|
|
115
|
+
signType: this.signType,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
|
|
120
|
+
*
|
|
121
|
+
* @param _ - The message to sign, as a string or BytesLike object.
|
|
122
|
+
* @returns A promise that resolves to the signature as a string.
|
|
123
|
+
* @throws Will throw an error if not implemented.
|
|
124
|
+
*/
|
|
125
|
+
signMessageRaw(_) {
|
|
126
|
+
throw Error("Signer.signMessageRaw not implemented");
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Verify a signature.
|
|
130
|
+
*
|
|
131
|
+
* @param _ - The original message.
|
|
132
|
+
* @param _ - The signature to verify.
|
|
133
|
+
* @returns A promise that resolves to the verification result.
|
|
134
|
+
* @throws Will throw an error if not implemented.
|
|
135
|
+
*/
|
|
136
|
+
async verifyMessage(message, signature) {
|
|
137
|
+
if (typeof signature === "string") {
|
|
138
|
+
return this.verifyMessageRaw(message, signature);
|
|
139
|
+
}
|
|
140
|
+
if (signature.identity !== (await this.getIdentity()) ||
|
|
141
|
+
![SignerSignType.Unknown, this.signType].includes(signature.signType)) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return this.verifyMessageRaw(message, signature.signature);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Verify a string signature. This method is not implemented and should be overridden by subclasses.
|
|
148
|
+
*
|
|
149
|
+
* @param _0 - The original message.
|
|
150
|
+
* @param _1 - The signature to verify.
|
|
151
|
+
* @returns A promise that resolves to the verification result.
|
|
152
|
+
* @throws Will throw an error if not implemented.
|
|
153
|
+
*/
|
|
154
|
+
verifyMessageRaw(_0, _1) {
|
|
155
|
+
throw Error("Signer.verifyMessageRaw not implemented");
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Sends a transaction after signing it.
|
|
159
|
+
*
|
|
160
|
+
* @param tx - The transaction to send, represented as a TransactionLike object.
|
|
161
|
+
* @returns A promise that resolves to the transaction hash as a Hex string.
|
|
162
|
+
*/
|
|
163
|
+
async sendTransaction(tx) {
|
|
164
|
+
return this.client.sendTransaction(await this.signTransaction(tx));
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Signs a transaction.
|
|
168
|
+
*
|
|
169
|
+
* @param tx - The transaction to sign, represented as a TransactionLike object.
|
|
170
|
+
* @returns A promise that resolves to the signed Transaction object.
|
|
171
|
+
*/
|
|
172
|
+
async signTransaction(tx) {
|
|
173
|
+
const preparedTx = await this.prepareTransaction(tx);
|
|
174
|
+
return this.signOnlyTransaction(preparedTx);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
178
|
+
*
|
|
179
|
+
* @param _ - The transaction to prepare, represented as a TransactionLike object.
|
|
180
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
181
|
+
* @throws Will throw an error if not implemented.
|
|
182
|
+
*/
|
|
183
|
+
prepareTransaction(_) {
|
|
184
|
+
throw Error("Signer.prepareTransaction not implemented");
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
|
|
188
|
+
*
|
|
189
|
+
* @param _ - The transaction to sign, represented as a TransactionLike object.
|
|
190
|
+
* @returns A promise that resolves to the signed Transaction object.
|
|
191
|
+
* @throws Will throw an error if not implemented.
|
|
192
|
+
*/
|
|
193
|
+
signOnlyTransaction(_) {
|
|
194
|
+
throw Error("Signer.signOnlyTransaction not implemented");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* A class representing information about a signer, including its type and the signer instance.
|
|
199
|
+
*/
|
|
200
|
+
export class SignerInfo {
|
|
201
|
+
constructor(name, signer) {
|
|
202
|
+
this.name = name;
|
|
203
|
+
this.signer = signer;
|
|
204
|
+
}
|
|
205
|
+
}
|