@arcblock/did-connect-js 1.25.6 → 1.26.0

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.
@@ -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
- return { sk: wallet.secretKey, pk: wallet.publicKey, address: wallet.address };
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
- return wallet;
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');
@@ -230,7 +229,7 @@ class WalletAuthenticator extends BaseAuthenticator {
230
229
 
231
230
  const result = {
232
231
  appPk: toBase58(wallet.pk),
233
- authInfo: Jwt.sign(wallet.address, wallet.sk, payload, true, didwallet ? didwallet.jwt : undefined),
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: Jwt.sign(wallet.address, wallet.sk, payload, true, version),
321
+ authInfo: await wallet.signJWT(payload, true, version),
323
322
  sensitive: claimsInfo.every((x) => ['keyPair', 'encryptionKey'].includes(x.type)),
324
323
  };
325
324
 
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.25.6",
4
+ "version": "1.26.0",
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.25.6",
28
- "@arcblock/jwt": "1.25.6",
29
- "@arcblock/validator": "1.25.6",
30
- "@ocap/client": "1.25.6",
31
- "@ocap/mcrypto": "1.25.6",
32
- "@ocap/util": "1.25.6",
33
- "@ocap/wallet": "1.25.6"
27
+ "@arcblock/did": "1.26.0",
28
+ "@arcblock/validator": "1.26.0",
29
+ "@arcblock/jwt": "1.26.0",
30
+ "@ocap/client": "1.26.0",
31
+ "@ocap/mcrypto": "1.26.0",
32
+ "@ocap/util": "1.26.0",
33
+ "@ocap/wallet": "1.26.0"
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.25.6"
43
+ "@ocap/e2e-test": "1.26.0"
44
44
  },
45
45
  "remarkConfig": {
46
46
  "plugins": [