@arcblock/did-connect-js 1.25.6 → 1.26.1
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/lib/authenticator/base.js +26 -3
- package/lib/authenticator/wallet.js +6 -5
- package/package.json +10 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-promise-executor-return */
|
|
2
2
|
const Jwt = require('@arcblock/jwt');
|
|
3
|
-
const { isValid } = require('@ocap/wallet');
|
|
3
|
+
const { isValid, fromJSON } = require('@ocap/wallet');
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line
|
|
6
6
|
const debug = require('debug')(`${require('../../package.json').name}:authenticator:base`);
|
|
@@ -16,9 +16,17 @@ class BaseAuthenticator {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
if (isValid(wallet, canSign)) {
|
|
19
|
-
|
|
19
|
+
// Full wallet object with methods - add pk/sk aliases for backward compatibility
|
|
20
|
+
if (!wallet.pk && wallet.publicKey) {
|
|
21
|
+
wallet.pk = wallet.publicKey;
|
|
22
|
+
}
|
|
23
|
+
if (!wallet.sk && wallet.secretKey) {
|
|
24
|
+
wallet.sk = wallet.secretKey;
|
|
25
|
+
}
|
|
26
|
+
return wallet;
|
|
20
27
|
}
|
|
21
28
|
|
|
29
|
+
// Validate required fields for JSON wallet object
|
|
22
30
|
if (canSign && !wallet.sk) {
|
|
23
31
|
throw new Error('WalletAuthenticator cannot work without wallet.sk');
|
|
24
32
|
}
|
|
@@ -29,7 +37,22 @@ class BaseAuthenticator {
|
|
|
29
37
|
throw new Error('WalletAuthenticator cannot work without wallet.address');
|
|
30
38
|
}
|
|
31
39
|
|
|
32
|
-
|
|
40
|
+
// If it's a plain JSON object with required fields, convert it to a full wallet object
|
|
41
|
+
// This ensures backward compatibility with code that uses toJSON()
|
|
42
|
+
try {
|
|
43
|
+
const fullWallet = fromJSON(wallet);
|
|
44
|
+
// Add pk/sk aliases for backward compatibility
|
|
45
|
+
if (!fullWallet.pk && fullWallet.publicKey) {
|
|
46
|
+
fullWallet.pk = fullWallet.publicKey;
|
|
47
|
+
}
|
|
48
|
+
if (!fullWallet.sk && fullWallet.secretKey) {
|
|
49
|
+
fullWallet.sk = fullWallet.secretKey;
|
|
50
|
+
}
|
|
51
|
+
return fullWallet;
|
|
52
|
+
} catch (err) {
|
|
53
|
+
// If fromJSON fails, return the original object for backward compatibility
|
|
54
|
+
return wallet;
|
|
55
|
+
}
|
|
33
56
|
}
|
|
34
57
|
|
|
35
58
|
/**
|
|
@@ -7,7 +7,6 @@ const random = require('lodash/random');
|
|
|
7
7
|
const shuffle = require('lodash/shuffle');
|
|
8
8
|
const isEqual = require('lodash/isEqual');
|
|
9
9
|
const Client = require('@ocap/client');
|
|
10
|
-
const Jwt = require('@arcblock/jwt');
|
|
11
10
|
const RSA = require('@ocap/mcrypto/lib/crypter/rsa').default;
|
|
12
11
|
const { toDid, toBase58, fromBase58 } = require('@ocap/util');
|
|
13
12
|
const { fromAddress } = require('@ocap/wallet');
|
|
@@ -113,7 +112,7 @@ class WalletAuthenticator extends BaseAuthenticator {
|
|
|
113
112
|
}) {
|
|
114
113
|
super();
|
|
115
114
|
|
|
116
|
-
this.wallet = this._validateWallet(wallet);
|
|
115
|
+
this.wallet = this._validateWallet(wallet, false);
|
|
117
116
|
this.appInfo = this._validateAppInfo(appInfo);
|
|
118
117
|
this.memberAppInfo = this._validateAppInfo(memberAppInfo, true);
|
|
119
118
|
this.chainInfo = chainInfo;
|
|
@@ -230,7 +229,7 @@ class WalletAuthenticator extends BaseAuthenticator {
|
|
|
230
229
|
|
|
231
230
|
const result = {
|
|
232
231
|
appPk: toBase58(wallet.pk),
|
|
233
|
-
authInfo:
|
|
232
|
+
authInfo: await wallet.signJWT(payload, true, didwallet ? didwallet.jwt : undefined),
|
|
234
233
|
};
|
|
235
234
|
|
|
236
235
|
if (delegator) {
|
|
@@ -319,7 +318,7 @@ class WalletAuthenticator extends BaseAuthenticator {
|
|
|
319
318
|
const version = context.didwallet ? context.didwallet.jwt : undefined;
|
|
320
319
|
const result = {
|
|
321
320
|
appPk: toBase58(wallet.pk),
|
|
322
|
-
authInfo:
|
|
321
|
+
authInfo: await wallet.signJWT(payload, true, version),
|
|
323
322
|
sensitive: claimsInfo.every((x) => ['keyPair', 'encryptionKey'].includes(x.type)),
|
|
324
323
|
};
|
|
325
324
|
|
|
@@ -400,8 +399,10 @@ class WalletAuthenticator extends BaseAuthenticator {
|
|
|
400
399
|
|
|
401
400
|
async getWalletInfo(params) {
|
|
402
401
|
if (typeof this.wallet === 'function') {
|
|
402
|
+
// No longer check wallet.secretKey, because we may have use cases (e.g. @arcblock/sdk)
|
|
403
|
+
// where there is no secretKey but we can still perform signing.
|
|
403
404
|
const result = await this.tryWithTimeout(() => this.wallet(params));
|
|
404
|
-
return this._validateWallet(result,
|
|
405
|
+
return this._validateWallet(result, false);
|
|
405
406
|
}
|
|
406
407
|
|
|
407
408
|
return this.wallet;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/did-connect-js",
|
|
3
3
|
"description": "Helper function to setup DID Connect support on a node.js web server",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.26.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "wangshijun",
|
|
7
7
|
"email": "shijun@arcblock.io",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"lodash": "^4.17.21",
|
|
25
25
|
"semver": "^7.6.3",
|
|
26
26
|
"tweetnacl-sealedbox-js": "^1.2.0",
|
|
27
|
-
"@arcblock/did": "1.
|
|
28
|
-
"@arcblock/jwt": "1.
|
|
29
|
-
"@arcblock/validator": "1.
|
|
30
|
-
"@ocap/client": "1.
|
|
31
|
-
"@ocap/mcrypto": "1.
|
|
32
|
-
"@ocap/util": "1.
|
|
33
|
-
"@ocap/wallet": "1.
|
|
27
|
+
"@arcblock/did": "1.26.1",
|
|
28
|
+
"@arcblock/jwt": "1.26.1",
|
|
29
|
+
"@arcblock/validator": "1.26.1",
|
|
30
|
+
"@ocap/client": "1.26.1",
|
|
31
|
+
"@ocap/mcrypto": "1.26.1",
|
|
32
|
+
"@ocap/util": "1.26.1",
|
|
33
|
+
"@ocap/wallet": "1.26.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@arcblock/did-agent-storage-memory": "^1.8.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"remark-cli": "^10.0.1",
|
|
41
41
|
"remark-preset-github": "^4.0.4",
|
|
42
42
|
"tweetnacl": "^1.0.3",
|
|
43
|
-
"@ocap/e2e-test": "1.
|
|
43
|
+
"@ocap/e2e-test": "1.26.1"
|
|
44
44
|
},
|
|
45
45
|
"remarkConfig": {
|
|
46
46
|
"plugins": [
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
]
|
|
53
53
|
]
|
|
54
54
|
},
|
|
55
|
-
"homepage": "https://
|
|
55
|
+
"homepage": "https://www.arcblock.io/docs/did-connect-sdk",
|
|
56
56
|
"keywords": [
|
|
57
57
|
"blockchain",
|
|
58
58
|
"arcblock",
|