@ocap/wallet 1.30.23 → 1.30.25
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/esm/index.d.mts +3 -1
- package/esm/index.mjs +26 -5
- package/lib/index.cjs +25 -4
- package/lib/index.d.cts +3 -1
- package/package.json +5 -5
package/esm/index.d.mts
CHANGED
|
@@ -14,6 +14,7 @@ type SerializedWallet = {
|
|
|
14
14
|
address: string;
|
|
15
15
|
method?: CryptoMethod;
|
|
16
16
|
};
|
|
17
|
+
type PublicSerializedWallet = Omit<SerializedWallet, 'sk'>;
|
|
17
18
|
interface WalletObject<T extends BytesType = string> {
|
|
18
19
|
type: DIDType;
|
|
19
20
|
method: CryptoMethod;
|
|
@@ -42,6 +43,7 @@ interface WalletObject<T extends BytesType = string> {
|
|
|
42
43
|
signETH(data: string, hashBeforeSign?: boolean): Promise<string>;
|
|
43
44
|
signJWT(payload?: any, doSign?: boolean, version?: string): Promise<string>;
|
|
44
45
|
toJSON(): SerializedWallet;
|
|
46
|
+
toPublicJSON(): PublicSerializedWallet;
|
|
45
47
|
/**
|
|
46
48
|
* @deprecated ES6: use `wallet.address` instead
|
|
47
49
|
*/
|
|
@@ -96,4 +98,4 @@ declare function fromJSON<T extends BytesType = string>(json: SerializedWallet):
|
|
|
96
98
|
*/
|
|
97
99
|
declare function isValid(wallet: WalletObject, canSign?: boolean): boolean;
|
|
98
100
|
//#endregion
|
|
99
|
-
export { SerializedWallet, Wallet, WalletObject, WalletType, fromAddress, fromJSON, fromPublicKey, fromRandom, fromSecretKey, isValid };
|
|
101
|
+
export { PublicSerializedWallet, SerializedWallet, Wallet, WalletObject, WalletType, fromAddress, fromJSON, fromPublicKey, fromRandom, fromSecretKey, isValid };
|
package/esm/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DidType, fromPublicKey as fromPublicKey$1, isCryptoMethod, toAddress, toTypeInfo } from "@arcblock/did";
|
|
2
2
|
import * as JWT from "@arcblock/jwt";
|
|
3
3
|
import { getHasher, getSigner } from "@ocap/mcrypto";
|
|
4
|
-
import { toHex } from "@ocap/util";
|
|
4
|
+
import { toHex, toUint8Array } from "@ocap/util";
|
|
5
5
|
|
|
6
6
|
//#region src/index.ts
|
|
7
|
+
const CUSTOM_INSPECT_SYMBOL = Symbol.for("nodejs.util.inspect.custom");
|
|
7
8
|
const WalletType = DidType;
|
|
8
9
|
/**
|
|
9
10
|
* Generate an wallet instance that can be used to sign a message or verify a signature
|
|
@@ -12,6 +13,9 @@ function Wallet(keyPair, t = "default") {
|
|
|
12
13
|
const type = DidType(t);
|
|
13
14
|
const signer = getSigner(type.pk);
|
|
14
15
|
const hasher = getHasher(type.hash);
|
|
16
|
+
if (keyPair.sk && keyPair.pk && typeof signer.getPublicKey === "function") {
|
|
17
|
+
if (toHex(toUint8Array(signer.getPublicKey(keyPair.sk))).toLowerCase() !== toHex(toUint8Array(keyPair.pk)).toLowerCase()) throw new Error("Public key does not match secret key");
|
|
18
|
+
}
|
|
15
19
|
return {
|
|
16
20
|
type,
|
|
17
21
|
method: keyPair.method && isCryptoMethod(keyPair.method) ? keyPair.method : "abt",
|
|
@@ -44,8 +48,8 @@ function Wallet(keyPair, t = "default") {
|
|
|
44
48
|
async signETH(data, hashBeforeSign = true) {
|
|
45
49
|
if (!keyPair.sk) throw new Error("Cannot sign data without a secretKey");
|
|
46
50
|
if (typeof signer.ethHash !== "function" || typeof signer.ethSign !== "function") throw new Error("ethSign is not supported by signer");
|
|
47
|
-
if (hashBeforeSign) return signer.ethSign(signer.ethHash(data), toHex(keyPair.sk));
|
|
48
|
-
return signer.ethSign(data, toHex(keyPair.sk));
|
|
51
|
+
if (hashBeforeSign) return signer.ethSign(signer.ethHash(data), toHex(toUint8Array(keyPair.sk)));
|
|
52
|
+
return signer.ethSign(data, toHex(toUint8Array(keyPair.sk)));
|
|
49
53
|
},
|
|
50
54
|
ethSign(data, hashBeforeSign = true) {
|
|
51
55
|
return this.signETH(data, hashBeforeSign);
|
|
@@ -65,11 +69,28 @@ function Wallet(keyPair, t = "default") {
|
|
|
65
69
|
toJSON() {
|
|
66
70
|
return {
|
|
67
71
|
type: DidType.toJSON(type),
|
|
68
|
-
sk: keyPair.sk ? toHex(keyPair.sk) : "",
|
|
69
|
-
pk: keyPair.pk ? toHex(keyPair.pk) : "",
|
|
72
|
+
sk: keyPair.sk ? toHex(toUint8Array(keyPair.sk)) : "",
|
|
73
|
+
pk: keyPair.pk ? toHex(toUint8Array(keyPair.pk)) : "",
|
|
74
|
+
address: this.address,
|
|
75
|
+
method: this.method
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
toPublicJSON() {
|
|
79
|
+
return {
|
|
80
|
+
type: DidType.toJSON(type),
|
|
81
|
+
pk: keyPair.pk ? toHex(toUint8Array(keyPair.pk)) : "",
|
|
70
82
|
address: this.address,
|
|
71
83
|
method: this.method
|
|
72
84
|
};
|
|
85
|
+
},
|
|
86
|
+
[CUSTOM_INSPECT_SYMBOL]() {
|
|
87
|
+
return {
|
|
88
|
+
type: DidType.toJSON(type),
|
|
89
|
+
method: this.method,
|
|
90
|
+
address: this.address,
|
|
91
|
+
publicKey: keyPair.pk ? toHex(toUint8Array(keyPair.pk)) : "",
|
|
92
|
+
secretKey: keyPair.sk ? "[REDACTED]" : ""
|
|
93
|
+
};
|
|
73
94
|
}
|
|
74
95
|
};
|
|
75
96
|
}
|
package/lib/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
|
6
6
|
let _ocap_util = require("@ocap/util");
|
|
7
7
|
|
|
8
8
|
//#region src/index.ts
|
|
9
|
+
const CUSTOM_INSPECT_SYMBOL = Symbol.for("nodejs.util.inspect.custom");
|
|
9
10
|
const WalletType = _arcblock_did.DidType;
|
|
10
11
|
/**
|
|
11
12
|
* Generate an wallet instance that can be used to sign a message or verify a signature
|
|
@@ -14,6 +15,9 @@ function Wallet(keyPair, t = "default") {
|
|
|
14
15
|
const type = (0, _arcblock_did.DidType)(t);
|
|
15
16
|
const signer = (0, _ocap_mcrypto.getSigner)(type.pk);
|
|
16
17
|
const hasher = (0, _ocap_mcrypto.getHasher)(type.hash);
|
|
18
|
+
if (keyPair.sk && keyPair.pk && typeof signer.getPublicKey === "function") {
|
|
19
|
+
if ((0, _ocap_util.toHex)((0, _ocap_util.toUint8Array)(signer.getPublicKey(keyPair.sk))).toLowerCase() !== (0, _ocap_util.toHex)((0, _ocap_util.toUint8Array)(keyPair.pk)).toLowerCase()) throw new Error("Public key does not match secret key");
|
|
20
|
+
}
|
|
17
21
|
return {
|
|
18
22
|
type,
|
|
19
23
|
method: keyPair.method && (0, _arcblock_did.isCryptoMethod)(keyPair.method) ? keyPair.method : "abt",
|
|
@@ -46,8 +50,8 @@ function Wallet(keyPair, t = "default") {
|
|
|
46
50
|
async signETH(data, hashBeforeSign = true) {
|
|
47
51
|
if (!keyPair.sk) throw new Error("Cannot sign data without a secretKey");
|
|
48
52
|
if (typeof signer.ethHash !== "function" || typeof signer.ethSign !== "function") throw new Error("ethSign is not supported by signer");
|
|
49
|
-
if (hashBeforeSign) return signer.ethSign(signer.ethHash(data), (0, _ocap_util.toHex)(keyPair.sk));
|
|
50
|
-
return signer.ethSign(data, (0, _ocap_util.toHex)(keyPair.sk));
|
|
53
|
+
if (hashBeforeSign) return signer.ethSign(signer.ethHash(data), (0, _ocap_util.toHex)((0, _ocap_util.toUint8Array)(keyPair.sk)));
|
|
54
|
+
return signer.ethSign(data, (0, _ocap_util.toHex)((0, _ocap_util.toUint8Array)(keyPair.sk)));
|
|
51
55
|
},
|
|
52
56
|
ethSign(data, hashBeforeSign = true) {
|
|
53
57
|
return this.signETH(data, hashBeforeSign);
|
|
@@ -67,11 +71,28 @@ function Wallet(keyPair, t = "default") {
|
|
|
67
71
|
toJSON() {
|
|
68
72
|
return {
|
|
69
73
|
type: _arcblock_did.DidType.toJSON(type),
|
|
70
|
-
sk: keyPair.sk ? (0, _ocap_util.toHex)(keyPair.sk) : "",
|
|
71
|
-
pk: keyPair.pk ? (0, _ocap_util.toHex)(keyPair.pk) : "",
|
|
74
|
+
sk: keyPair.sk ? (0, _ocap_util.toHex)((0, _ocap_util.toUint8Array)(keyPair.sk)) : "",
|
|
75
|
+
pk: keyPair.pk ? (0, _ocap_util.toHex)((0, _ocap_util.toUint8Array)(keyPair.pk)) : "",
|
|
76
|
+
address: this.address,
|
|
77
|
+
method: this.method
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
toPublicJSON() {
|
|
81
|
+
return {
|
|
82
|
+
type: _arcblock_did.DidType.toJSON(type),
|
|
83
|
+
pk: keyPair.pk ? (0, _ocap_util.toHex)((0, _ocap_util.toUint8Array)(keyPair.pk)) : "",
|
|
72
84
|
address: this.address,
|
|
73
85
|
method: this.method
|
|
74
86
|
};
|
|
87
|
+
},
|
|
88
|
+
[CUSTOM_INSPECT_SYMBOL]() {
|
|
89
|
+
return {
|
|
90
|
+
type: _arcblock_did.DidType.toJSON(type),
|
|
91
|
+
method: this.method,
|
|
92
|
+
address: this.address,
|
|
93
|
+
publicKey: keyPair.pk ? (0, _ocap_util.toHex)((0, _ocap_util.toUint8Array)(keyPair.pk)) : "",
|
|
94
|
+
secretKey: keyPair.sk ? "[REDACTED]" : ""
|
|
95
|
+
};
|
|
75
96
|
}
|
|
76
97
|
};
|
|
77
98
|
}
|
package/lib/index.d.cts
CHANGED
|
@@ -14,6 +14,7 @@ type SerializedWallet = {
|
|
|
14
14
|
address: string;
|
|
15
15
|
method?: CryptoMethod;
|
|
16
16
|
};
|
|
17
|
+
type PublicSerializedWallet = Omit<SerializedWallet, 'sk'>;
|
|
17
18
|
interface WalletObject<T extends BytesType = string> {
|
|
18
19
|
type: DIDType;
|
|
19
20
|
method: CryptoMethod;
|
|
@@ -42,6 +43,7 @@ interface WalletObject<T extends BytesType = string> {
|
|
|
42
43
|
signETH(data: string, hashBeforeSign?: boolean): Promise<string>;
|
|
43
44
|
signJWT(payload?: any, doSign?: boolean, version?: string): Promise<string>;
|
|
44
45
|
toJSON(): SerializedWallet;
|
|
46
|
+
toPublicJSON(): PublicSerializedWallet;
|
|
45
47
|
/**
|
|
46
48
|
* @deprecated ES6: use `wallet.address` instead
|
|
47
49
|
*/
|
|
@@ -96,4 +98,4 @@ declare function fromJSON<T extends BytesType = string>(json: SerializedWallet):
|
|
|
96
98
|
*/
|
|
97
99
|
declare function isValid(wallet: WalletObject, canSign?: boolean): boolean;
|
|
98
100
|
//#endregion
|
|
99
|
-
export { SerializedWallet, Wallet, WalletObject, WalletType, fromAddress, fromJSON, fromPublicKey, fromRandom, fromSecretKey, isValid };
|
|
101
|
+
export { PublicSerializedWallet, SerializedWallet, Wallet, WalletObject, WalletType, fromAddress, fromJSON, fromPublicKey, fromRandom, fromSecretKey, isValid };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/wallet",
|
|
3
|
-
"version": "1.30.
|
|
3
|
+
"version": "1.30.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Utility function to create and use an forge compatible crypto wallet",
|
|
6
6
|
"keywords": [
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"url": "https://github.com/ArcBlock/blockchain/issues"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@arcblock/did": "1.30.
|
|
61
|
-
"@arcblock/jwt": "1.30.
|
|
62
|
-
"@ocap/mcrypto": "1.30.
|
|
63
|
-
"@ocap/util": "1.30.
|
|
60
|
+
"@arcblock/did": "1.30.25",
|
|
61
|
+
"@arcblock/jwt": "1.30.25",
|
|
62
|
+
"@ocap/mcrypto": "1.30.25",
|
|
63
|
+
"@ocap/util": "1.30.25"
|
|
64
64
|
}
|
|
65
65
|
}
|