@ocap/wallet 1.29.18 → 1.29.19
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 +7 -2
- package/esm/index.mjs +13 -4
- package/lib/index.cjs +12 -3
- package/lib/index.d.cts +7 -2
- package/package.json +5 -5
package/esm/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DIDType, DIDTypeArg, DIDTypeStr, DidType } from "@arcblock/did";
|
|
1
|
+
import { CryptoMethod, DIDType, DIDTypeArg, DIDTypeStr, DidType } from "@arcblock/did";
|
|
2
2
|
import { BytesType, EncodingType } from "@ocap/util";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
@@ -12,12 +12,15 @@ type SerializedWallet = {
|
|
|
12
12
|
pk: string;
|
|
13
13
|
sk: string;
|
|
14
14
|
address: string;
|
|
15
|
+
method?: CryptoMethod;
|
|
15
16
|
};
|
|
16
17
|
interface WalletObject<T extends BytesType = string> {
|
|
17
18
|
type: DIDType;
|
|
19
|
+
method: CryptoMethod;
|
|
18
20
|
secretKey: T;
|
|
19
21
|
publicKey: T;
|
|
20
22
|
address: string;
|
|
23
|
+
toDid(): string;
|
|
21
24
|
hash(data: BytesType, round?: number, encoding?: 'hex'): string;
|
|
22
25
|
hash(data: BytesType, round?: number, encoding?: 'base16'): string;
|
|
23
26
|
hash(data: BytesType, round?: number, encoding?: 'base58'): string;
|
|
@@ -48,7 +51,9 @@ declare const WalletType: typeof DidType;
|
|
|
48
51
|
/**
|
|
49
52
|
* Generate an wallet instance that can be used to sign a message or verify a signature
|
|
50
53
|
*/
|
|
51
|
-
declare function Wallet<T extends BytesType = string>(keyPair: KeyPairType<T
|
|
54
|
+
declare function Wallet<T extends BytesType = string>(keyPair: KeyPairType<T> & {
|
|
55
|
+
method?: CryptoMethod;
|
|
56
|
+
}, t?: DIDTypeArg): WalletObject<T>;
|
|
52
57
|
/**
|
|
53
58
|
* Generate a wallet from secretKey
|
|
54
59
|
*
|
package/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DidType, fromPublicKey as fromPublicKey$1, toAddress, toTypeInfo } from "@arcblock/did";
|
|
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
4
|
import { toHex } from "@ocap/util";
|
|
@@ -14,9 +14,13 @@ function Wallet(keyPair, t = "default") {
|
|
|
14
14
|
const hasher = getHasher(type.hash);
|
|
15
15
|
return {
|
|
16
16
|
type,
|
|
17
|
+
method: keyPair.method && isCryptoMethod(keyPair.method) ? keyPair.method : "abt",
|
|
17
18
|
secretKey: keyPair.sk,
|
|
18
19
|
publicKey: keyPair.pk,
|
|
19
20
|
address: keyPair.pk ? fromPublicKey$1(keyPair.pk, type) : keyPair.address,
|
|
21
|
+
toDid() {
|
|
22
|
+
return `did:${this.method}:${this.address}`;
|
|
23
|
+
},
|
|
20
24
|
hash(data, round = 1, encoding = "hex") {
|
|
21
25
|
return hasher(data, round, encoding);
|
|
22
26
|
},
|
|
@@ -53,7 +57,7 @@ function Wallet(keyPair, t = "default") {
|
|
|
53
57
|
},
|
|
54
58
|
async signJWT(payload = {}, doSign = true, version = "1.0.0") {
|
|
55
59
|
if (!keyPair.sk) throw new Error("Cannot sign JWT without a secretKey");
|
|
56
|
-
return JWT.sign(this.
|
|
60
|
+
return JWT.sign(this.toDid(), keyPair.sk, payload, doSign, version);
|
|
57
61
|
},
|
|
58
62
|
toAddress() {
|
|
59
63
|
return keyPair.pk ? fromPublicKey$1(keyPair.pk, type) : keyPair.address;
|
|
@@ -63,7 +67,8 @@ function Wallet(keyPair, t = "default") {
|
|
|
63
67
|
type: DidType.toJSON(type),
|
|
64
68
|
sk: keyPair.sk ? toHex(keyPair.sk) : "",
|
|
65
69
|
pk: keyPair.pk ? toHex(keyPair.pk) : "",
|
|
66
|
-
address: this.address
|
|
70
|
+
address: this.address,
|
|
71
|
+
method: this.method
|
|
67
72
|
};
|
|
68
73
|
}
|
|
69
74
|
};
|
|
@@ -122,7 +127,11 @@ function fromRandom(_type = "default") {
|
|
|
122
127
|
* Generating a wallet from a serialized json presentation of another wallet
|
|
123
128
|
*/
|
|
124
129
|
function fromJSON(json) {
|
|
125
|
-
|
|
130
|
+
const type = DidType.fromJSON(json.type);
|
|
131
|
+
return Wallet({
|
|
132
|
+
...json,
|
|
133
|
+
method: json.method
|
|
134
|
+
}, type);
|
|
126
135
|
}
|
|
127
136
|
/**
|
|
128
137
|
* Check if an object is valid wallet object
|
package/lib/index.cjs
CHANGED
|
@@ -16,9 +16,13 @@ function Wallet(keyPair, t = "default") {
|
|
|
16
16
|
const hasher = (0, _ocap_mcrypto.getHasher)(type.hash);
|
|
17
17
|
return {
|
|
18
18
|
type,
|
|
19
|
+
method: keyPair.method && (0, _arcblock_did.isCryptoMethod)(keyPair.method) ? keyPair.method : "abt",
|
|
19
20
|
secretKey: keyPair.sk,
|
|
20
21
|
publicKey: keyPair.pk,
|
|
21
22
|
address: keyPair.pk ? (0, _arcblock_did.fromPublicKey)(keyPair.pk, type) : keyPair.address,
|
|
23
|
+
toDid() {
|
|
24
|
+
return `did:${this.method}:${this.address}`;
|
|
25
|
+
},
|
|
22
26
|
hash(data, round = 1, encoding = "hex") {
|
|
23
27
|
return hasher(data, round, encoding);
|
|
24
28
|
},
|
|
@@ -55,7 +59,7 @@ function Wallet(keyPair, t = "default") {
|
|
|
55
59
|
},
|
|
56
60
|
async signJWT(payload = {}, doSign = true, version = "1.0.0") {
|
|
57
61
|
if (!keyPair.sk) throw new Error("Cannot sign JWT without a secretKey");
|
|
58
|
-
return _arcblock_jwt.sign(this.
|
|
62
|
+
return _arcblock_jwt.sign(this.toDid(), keyPair.sk, payload, doSign, version);
|
|
59
63
|
},
|
|
60
64
|
toAddress() {
|
|
61
65
|
return keyPair.pk ? (0, _arcblock_did.fromPublicKey)(keyPair.pk, type) : keyPair.address;
|
|
@@ -65,7 +69,8 @@ function Wallet(keyPair, t = "default") {
|
|
|
65
69
|
type: _arcblock_did.DidType.toJSON(type),
|
|
66
70
|
sk: keyPair.sk ? (0, _ocap_util.toHex)(keyPair.sk) : "",
|
|
67
71
|
pk: keyPair.pk ? (0, _ocap_util.toHex)(keyPair.pk) : "",
|
|
68
|
-
address: this.address
|
|
72
|
+
address: this.address,
|
|
73
|
+
method: this.method
|
|
69
74
|
};
|
|
70
75
|
}
|
|
71
76
|
};
|
|
@@ -124,7 +129,11 @@ function fromRandom(_type = "default") {
|
|
|
124
129
|
* Generating a wallet from a serialized json presentation of another wallet
|
|
125
130
|
*/
|
|
126
131
|
function fromJSON(json) {
|
|
127
|
-
|
|
132
|
+
const type = _arcblock_did.DidType.fromJSON(json.type);
|
|
133
|
+
return Wallet({
|
|
134
|
+
...json,
|
|
135
|
+
method: json.method
|
|
136
|
+
}, type);
|
|
128
137
|
}
|
|
129
138
|
/**
|
|
130
139
|
* Check if an object is valid wallet object
|
package/lib/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DIDType, DIDTypeArg, DIDTypeStr, DidType } from "@arcblock/did";
|
|
1
|
+
import { CryptoMethod, DIDType, DIDTypeArg, DIDTypeStr, DidType } from "@arcblock/did";
|
|
2
2
|
import { BytesType, EncodingType } from "@ocap/util";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
@@ -12,12 +12,15 @@ type SerializedWallet = {
|
|
|
12
12
|
pk: string;
|
|
13
13
|
sk: string;
|
|
14
14
|
address: string;
|
|
15
|
+
method?: CryptoMethod;
|
|
15
16
|
};
|
|
16
17
|
interface WalletObject<T extends BytesType = string> {
|
|
17
18
|
type: DIDType;
|
|
19
|
+
method: CryptoMethod;
|
|
18
20
|
secretKey: T;
|
|
19
21
|
publicKey: T;
|
|
20
22
|
address: string;
|
|
23
|
+
toDid(): string;
|
|
21
24
|
hash(data: BytesType, round?: number, encoding?: 'hex'): string;
|
|
22
25
|
hash(data: BytesType, round?: number, encoding?: 'base16'): string;
|
|
23
26
|
hash(data: BytesType, round?: number, encoding?: 'base58'): string;
|
|
@@ -48,7 +51,9 @@ declare const WalletType: typeof DidType;
|
|
|
48
51
|
/**
|
|
49
52
|
* Generate an wallet instance that can be used to sign a message or verify a signature
|
|
50
53
|
*/
|
|
51
|
-
declare function Wallet<T extends BytesType = string>(keyPair: KeyPairType<T
|
|
54
|
+
declare function Wallet<T extends BytesType = string>(keyPair: KeyPairType<T> & {
|
|
55
|
+
method?: CryptoMethod;
|
|
56
|
+
}, t?: DIDTypeArg): WalletObject<T>;
|
|
52
57
|
/**
|
|
53
58
|
* Generate a wallet from secretKey
|
|
54
59
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/wallet",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.19",
|
|
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.29.
|
|
61
|
-
"@arcblock/jwt": "1.29.
|
|
62
|
-
"@ocap/mcrypto": "1.29.
|
|
63
|
-
"@ocap/util": "1.29.
|
|
60
|
+
"@arcblock/did": "1.29.19",
|
|
61
|
+
"@arcblock/jwt": "1.29.19",
|
|
62
|
+
"@ocap/mcrypto": "1.29.19",
|
|
63
|
+
"@ocap/util": "1.29.19"
|
|
64
64
|
}
|
|
65
65
|
}
|