@ocap/wallet 1.6.5 → 1.6.10
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +36 -1
- package/package.json +14 -12
package/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
|
4
4
|
[![docs](https://img.shields.io/badge/powered%20by-arcblock-green.svg)](https://docs.arcblock.io)
|
5
|
-
[![Gitter](https://badges.gitter.im/ArcBlock/community.svg)](https://gitter.im/ArcBlock/community?utm_source=badge
|
5
|
+
[![Gitter](https://badges.gitter.im/ArcBlock/community.svg)](https://gitter.im/ArcBlock/community?utm_source=badge\&utm_medium=badge\&utm_campaign=pr-badge)
|
6
6
|
|
7
7
|
> Utility function to create and use a forge compatible wallet, the wallet is also DID compatible.
|
8
8
|
|
@@ -44,4 +44,4 @@ const wallet2 = fromJSON(wallet.toJSON());
|
|
44
44
|
|
45
45
|
## Documentation
|
46
46
|
|
47
|
-
For full documentation, checkout [https://
|
47
|
+
For full documentation, checkout [https://asset-chain.netlify.com](https://asset-chain.netlify.com/)
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
@@ -43,10 +43,12 @@ function Wallet(keyPair, type = 'default') {
|
|
43
43
|
type,
|
44
44
|
secretKey: keyPair.sk,
|
45
45
|
publicKey: keyPair.pk,
|
46
|
+
address: keyPair.pk ? DIDFromPublicKey(keyPair.pk, type) : keyPair.address,
|
46
47
|
|
47
48
|
hash(data, round = 1) {
|
48
49
|
return hasher(data, round);
|
49
50
|
},
|
51
|
+
|
50
52
|
sign(data, hashBeforeSign = true) {
|
51
53
|
if (!keyPair.sk) {
|
52
54
|
throw new Error('Cannot sign data without a secretKey');
|
@@ -60,6 +62,7 @@ function Wallet(keyPair, type = 'default') {
|
|
60
62
|
|
61
63
|
return signer.sign(data, keyPair.sk);
|
62
64
|
},
|
65
|
+
|
63
66
|
verify(data, signature, hashBeforeVerify = true) {
|
64
67
|
if (!keyPair.pk) {
|
65
68
|
throw new Error('Cannot verify data without a publicKey');
|
@@ -68,15 +71,47 @@ function Wallet(keyPair, type = 'default') {
|
|
68
71
|
// console.log('verify.hash', hash.replace(/^0x/i, '').toUpperCase());
|
69
72
|
return signer.verify(hash, signature, keyPair.pk);
|
70
73
|
},
|
74
|
+
|
75
|
+
ethHash(data) {
|
76
|
+
if (typeof signer.ethHash !== 'function') {
|
77
|
+
throw new Error('ethHash is not supported by signer');
|
78
|
+
}
|
79
|
+
return signer.ethHash(data);
|
80
|
+
},
|
81
|
+
|
82
|
+
ethSign(data, hashBeforeSign = true) {
|
83
|
+
if (!keyPair.sk) {
|
84
|
+
throw new Error('Cannot sign data without a secretKey');
|
85
|
+
}
|
86
|
+
if (typeof signer.ethHash !== 'function') {
|
87
|
+
throw new Error('ethSign is not supported by signer');
|
88
|
+
}
|
89
|
+
|
90
|
+
if (hashBeforeSign) {
|
91
|
+
return signer.ethSign(signer.ethHash(data), keyPair.sk);
|
92
|
+
}
|
93
|
+
|
94
|
+
return signer.ethSign(data, keyPair.sk);
|
95
|
+
},
|
96
|
+
|
97
|
+
ethVerify(data, signature, hashBeforeVerify = true) {
|
98
|
+
if (typeof signer.ethHash !== 'function') {
|
99
|
+
throw new Error('ethVerify is not supported by signer');
|
100
|
+
}
|
101
|
+
const hash = hashBeforeVerify ? signer.ethHash(data) : data;
|
102
|
+
return signer.ethRecover(hash, signature) === this.address;
|
103
|
+
},
|
104
|
+
|
71
105
|
toAddress() {
|
72
106
|
return keyPair.pk ? DIDFromPublicKey(keyPair.pk, type) : keyPair.address;
|
73
107
|
},
|
108
|
+
|
74
109
|
toJSON() {
|
75
110
|
return {
|
76
111
|
type: DidType.toJSON(type),
|
77
112
|
sk: keyPair.sk,
|
78
113
|
pk: keyPair.pk,
|
79
|
-
address: this.
|
114
|
+
address: this.address,
|
80
115
|
};
|
81
116
|
},
|
82
117
|
};
|
package/package.json
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ocap/wallet",
|
3
|
-
"version": "1.6.
|
3
|
+
"version": "1.6.10",
|
4
4
|
"description": "Utility function to create and use an forge compatible crypto wallet",
|
5
5
|
"keywords": [
|
6
6
|
"crypto",
|
7
|
-
"forge",
|
8
7
|
"arcblock",
|
9
8
|
"wallet"
|
10
9
|
],
|
@@ -16,37 +15,40 @@
|
|
16
15
|
"email": "shijun@arcblock.io",
|
17
16
|
"url": "https://github.com/wangshijun"
|
18
17
|
},
|
19
|
-
"
|
18
|
+
"contributors": [
|
19
|
+
"wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
|
20
|
+
],
|
21
|
+
"homepage": "https://github.com/ArcBlock/asset-chain/tree/master/core/forge-wallet",
|
20
22
|
"license": "Apache-2.0",
|
21
23
|
"main": "lib/index.js",
|
22
24
|
"files": [
|
23
25
|
"lib"
|
24
26
|
],
|
25
27
|
"devDependencies": {
|
26
|
-
"jest": "^
|
27
|
-
"jsdoc-to-markdown": "^
|
28
|
+
"jest": "^27.3.1",
|
29
|
+
"jsdoc-to-markdown": "^7.1.1"
|
28
30
|
},
|
29
31
|
"repository": {
|
30
32
|
"type": "git",
|
31
|
-
"url": "git+https://github.com/ArcBlock/
|
33
|
+
"url": "git+https://github.com/ArcBlock/asset-chain.git"
|
32
34
|
},
|
33
35
|
"scripts": {
|
34
36
|
"lint": "eslint tests lib",
|
35
37
|
"lint:fix": "eslint --fix tests lib",
|
36
38
|
"docs": "yarn gen-dts && yarn gen-docs && yarn cleanup-docs && yarn format-docs",
|
37
|
-
"cleanup-docs": "node ../../
|
39
|
+
"cleanup-docs": "node ../../scripts/cleanup-docs.js docs/README.md $npm_package_name",
|
38
40
|
"gen-docs": "jsdoc2md lib/index.js > docs/README.md",
|
39
41
|
"gen-dts": "j2d lib/index.js",
|
40
42
|
"format-docs": "remark . -o",
|
41
|
-
"test": "
|
43
|
+
"test": "jest --forceExit --detectOpenHandles",
|
42
44
|
"coverage": "yarn test -- --coverage"
|
43
45
|
},
|
44
46
|
"bugs": {
|
45
|
-
"url": "https://github.com/ArcBlock/
|
47
|
+
"url": "https://github.com/ArcBlock/asset-chain/issues"
|
46
48
|
},
|
47
49
|
"dependencies": {
|
48
|
-
"@arcblock/did": "
|
49
|
-
"@ocap/mcrypto": "
|
50
|
+
"@arcblock/did": "1.6.10",
|
51
|
+
"@ocap/mcrypto": "1.6.10"
|
50
52
|
},
|
51
|
-
"gitHead": "
|
53
|
+
"gitHead": "ab272e8db3a15c6571cc7fae7cc3d3e0fdd4bdb1"
|
52
54
|
}
|