@abtnode/auth 1.16.0 → 1.16.1-beta-cd775909

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/auth.js CHANGED
@@ -5,9 +5,9 @@ const joinUrl = require('url-join');
5
5
  const get = require('lodash/get');
6
6
  const { verifyPresentation, createCredentialList } = require('@arcblock/vc');
7
7
  const formatContext = require('@abtnode/util/lib/format-context');
8
+ const getNodeWallet = require('@abtnode/util/lib/get-app-wallet');
8
9
  const Mcrypto = require('@ocap/mcrypto');
9
10
  const Client = require('@ocap/client');
10
- const { fromSecretKey, WalletType } = require('@ocap/wallet');
11
11
  const getBlockletInfo = require('@blocklet/meta/lib/info');
12
12
  const {
13
13
  PASSPORT_STATUS,
@@ -284,22 +284,6 @@ const getPassportStatusEndpoint = ({ baseUrl, userDid, teamDid }) => {
284
284
  return joinUrl(baseUrl, `/api/passport/status?userDid=${userDid}&teamDid=${teamDid}`);
285
285
  };
286
286
 
287
- /**
288
- * Get wallet of abtnode from sk
289
- * @param {String} sk
290
- * @returns {Wallet}
291
- */
292
- const getNodeWallet = (sk) => {
293
- const { types } = Mcrypto;
294
- const type = WalletType({
295
- role: types.RoleType.ROLE_APPLICATION,
296
- pk: types.KeyType.ED25519,
297
- hash: types.HashType.SHA3,
298
- });
299
-
300
- return fromSecretKey(sk, type);
301
- };
302
-
303
287
  const getRandomMessage = (len = 16) => {
304
288
  const hex = Mcrypto.getRandomBytes(len);
305
289
  return hex.replace(/^0x/, '').toUpperCase();
@@ -901,24 +885,33 @@ const getVCFromClaims = async ({ claims, challenge, trustedIssuers, vcTypes, loc
901
885
  };
902
886
  };
903
887
 
904
- const checkWalletVersion = ({ didwallet, locale = 'en' }) => {
888
+ const checkWalletVersion = ({ didwallet, locale = 'en', expected = {} }) => {
905
889
  const { os, version } = didwallet;
906
890
 
907
- const defaultExpected = '3.0.0';
891
+ const defaultExpected = '4.0.0';
908
892
 
909
- const expected = {
910
- android: defaultExpected,
911
- ios: defaultExpected,
912
- web: defaultExpected,
893
+ const expectedWallet = {
894
+ android: expected.android || defaultExpected,
895
+ ios: expected.ios || defaultExpected,
896
+ web: expected.web || defaultExpected,
913
897
  };
914
898
 
915
- if (semver.lt(version, expected[os] || defaultExpected)) {
916
- throw new Error(messages.lowVersion[locale]);
899
+ if (semver.lt(version, expectedWallet[os] || defaultExpected)) {
900
+ throw new Error(messages.lowVersion[locale || 'en']);
917
901
  }
918
902
 
919
903
  return true;
920
904
  };
921
905
 
906
+ const checkWalletVersionForMigrateAppToV2 = (param) => {
907
+ param.expected = {
908
+ android: '4.11.15',
909
+ ios: '4.11.29',
910
+ web: '4.6.12',
911
+ };
912
+ return checkWalletVersion(param);
913
+ };
914
+
922
915
  const getPassportStatus = async ({ node, teamDid, userDid, vcId, locale = 'en' }) => {
923
916
  const nodeInfo = await node.getNodeInfo();
924
917
  const {
@@ -1078,6 +1071,7 @@ module.exports = {
1078
1071
  getVCFromClaims,
1079
1072
  messages,
1080
1073
  checkWalletVersion,
1074
+ checkWalletVersionForMigrateAppToV2,
1081
1075
  getPassportStatusEndpoint,
1082
1076
  getPassportStatus,
1083
1077
  validatePassportStatus,
package/lib/server.js CHANGED
@@ -14,7 +14,8 @@ const { toTypeInfo, isFromPublicKey, DidType, isEthereumType } = require('@arcbl
14
14
  const urlFriendly = require('@blocklet/meta/lib/url-friendly').default;
15
15
  const getApplicationWallet = require('@blocklet/meta/lib/wallet');
16
16
  const { slugify } = require('transliteration');
17
- const { getChainInfo } = require('@blocklet/meta/lib/util');
17
+ const { getBlockletChainInfo } = require('@blocklet/meta/lib/util');
18
+
18
19
  const getBlockletInfo = require('@blocklet/meta/lib/info');
19
20
  const formatContext = require('@abtnode/util/lib/format-context');
20
21
  const {
@@ -36,6 +37,7 @@ const {
36
37
  createAuthTokenByOwnershipNFT,
37
38
  createBlockletControllerAuthToken,
38
39
  checkWalletVersion,
40
+ checkWalletVersionForMigrateAppToV2,
39
41
  } = require('./auth');
40
42
  const {
41
43
  validatePassport,
@@ -330,6 +332,46 @@ const getAuthNFTClaim =
330
332
  return getOwnershipNFTClaim(node, locale);
331
333
  };
332
334
 
335
+ const getAuthPrincipalForMigrateAppToV2 = (node) => async (param) => {
336
+ const {
337
+ extraParams: { locale, appDid },
338
+ context: { didwallet },
339
+ } = param;
340
+
341
+ checkWalletVersionForMigrateAppToV2({
342
+ didwallet,
343
+ local: locale,
344
+ });
345
+
346
+ if (!appDid) {
347
+ throw new Error('appDid is required in extraParams');
348
+ }
349
+
350
+ const blocklet = await node.getBlocklet({ did: appDid, attachRuntimeInfo: false });
351
+ if (!blocklet) {
352
+ throw new Error(messages.invalidBlocklet[locale]);
353
+ }
354
+
355
+ const info = await node.getNodeInfo();
356
+ const { wallet } = getBlockletInfo(blocklet, info.sk);
357
+ const type = DidType(wallet.type);
358
+
359
+ // get chain info
360
+ let chainInfo = getBlockletChainInfo(blocklet);
361
+ if (isEthereumType(type)) {
362
+ chainInfo.type = 'ethereum';
363
+ chainInfo.id = '1';
364
+ }
365
+ if (chainInfo.host === 'none') {
366
+ chainInfo = { host: MAIN_CHAIN_ENDPOINT, id: 'main', type: 'arcblock' };
367
+ }
368
+
369
+ return {
370
+ description: 'Please select account to continue',
371
+ chainInfo,
372
+ };
373
+ };
374
+
333
375
  const getKeyPairClaim =
334
376
  (node, declare = true) =>
335
377
  async ({ extraParams: { locale, appDid, wt = 'default', title }, context: { didwallet } }) => {
@@ -358,11 +400,11 @@ const getKeyPairClaim =
358
400
  appName = name;
359
401
  migrateFrom = wallet.address;
360
402
  type = DidType(wallet.type);
361
- chainInfo = getChainInfo(blocklet.configObj);
403
+ chainInfo = getBlockletChainInfo(blocklet);
362
404
  } else {
363
405
  type = DidType(wt);
364
406
  type.role = types.RoleType.ROLE_APPLICATION;
365
- chainInfo = getChainInfo({});
407
+ chainInfo = getBlockletChainInfo();
366
408
  }
367
409
 
368
410
  const typeStr = DidType.toJSON(type);
@@ -376,8 +418,8 @@ const getKeyPairClaim =
376
418
  description: description[locale] || description.en,
377
419
  moniker: (urlFriendly(slugify(appName)) || 'application').toLowerCase(),
378
420
  declare: !!declare,
421
+ migrateFrom: declare ? migrateFrom : '',
379
422
  chainInfo,
380
- migrateFrom,
381
423
  targetType: {
382
424
  role: typeStr.role?.split('_').pop()?.toLowerCase(),
383
425
  key: typeStr.pk?.toLowerCase(),
@@ -415,7 +457,7 @@ const getRotateKeyPairClaims = (node) => {
415
457
  // Try to use blocklet chain config if possible
416
458
  // Since migration happens on the chain the app holds some actual assets
417
459
  // We must ensure it happens on that chain
418
- chainInfo = getChainInfo(blocklet.configObj);
460
+ chainInfo = getBlockletChainInfo(blocklet);
419
461
 
420
462
  // Fallback to main chain, since it is the default registry for all DID
421
463
  if (chainInfo.host === 'none') {
@@ -806,4 +848,5 @@ module.exports = {
806
848
  getAuthNFTClaim,
807
849
  getServerlessNFTClaim,
808
850
  getLauncherAppIdList,
851
+ getAuthPrincipalForMigrateAppToV2,
809
852
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.0",
6
+ "version": "1.16.1-beta-cd775909",
7
7
  "description": "Simple lib to manage auth in ABT Node",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -20,14 +20,14 @@
20
20
  "author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@abtnode/constant": "1.16.0",
24
- "@abtnode/logger": "1.16.0",
25
- "@abtnode/util": "1.16.0",
23
+ "@abtnode/constant": "1.16.1-beta-cd775909",
24
+ "@abtnode/logger": "1.16.1-beta-cd775909",
25
+ "@abtnode/util": "1.16.1-beta-cd775909",
26
26
  "@arcblock/did": "1.18.65",
27
27
  "@arcblock/jwt": "^1.18.65",
28
28
  "@arcblock/vc": "1.18.65",
29
- "@blocklet/constant": "1.16.0",
30
- "@blocklet/meta": "1.16.0",
29
+ "@blocklet/constant": "1.16.1-beta-cd775909",
30
+ "@blocklet/meta": "1.16.1-beta-cd775909",
31
31
  "@ocap/client": "1.18.65",
32
32
  "@ocap/mcrypto": "1.18.65",
33
33
  "@ocap/util": "1.18.65",
@@ -44,5 +44,5 @@
44
44
  "devDependencies": {
45
45
  "jest": "^27.5.1"
46
46
  },
47
- "gitHead": "da461546c6db9c7d347689708af27654c17ac28e"
47
+ "gitHead": "9fd68e48cd87d5d8feafcf37dac1b586c1dccd8f"
48
48
  }