@blocklet/sdk 1.16.14-beta-1936d3d0 → 1.16.14-beta-dc99d0a2
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/connect/authenticator.d.ts +1 -0
- package/lib/connect/authenticator.js +2 -0
- package/lib/connect/shared.d.ts +6 -2
- package/lib/connect/shared.js +57 -5
- package/lib/service/auth.d.ts +1 -0
- package/lib/service/auth.js +5 -0
- package/lib/wallet-authenticator.d.ts +1 -0
- package/lib/wallet-authenticator.js +2 -0
- package/package.json +9 -9
|
@@ -6,6 +6,7 @@ const authenticator_1 = require("@did-connect/authenticator");
|
|
|
6
6
|
const wallet_1 = __importDefault(require("../wallet"));
|
|
7
7
|
const check_blocklet_env_1 = __importDefault(require("../util/check-blocklet-env"));
|
|
8
8
|
const shared_1 = require("./shared");
|
|
9
|
+
const auth_1 = __importDefault(require("../service/auth"));
|
|
9
10
|
class BlockletAuthenticator extends authenticator_1.Authenticator {
|
|
10
11
|
constructor(options = {}) {
|
|
11
12
|
(0, check_blocklet_env_1.default)();
|
|
@@ -13,6 +14,7 @@ class BlockletAuthenticator extends authenticator_1.Authenticator {
|
|
|
13
14
|
wallet: (0, wallet_1.default)(),
|
|
14
15
|
...(0, shared_1.getAuthenticatorProps)(options),
|
|
15
16
|
});
|
|
17
|
+
this.authClient = new auth_1.default();
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
module.exports = BlockletAuthenticator;
|
package/lib/connect/shared.d.ts
CHANGED
|
@@ -12,8 +12,12 @@ declare const getAuthenticatorProps: (options?: {}) => {
|
|
|
12
12
|
subscriptionEndpoint: string;
|
|
13
13
|
nodeDid: string | undefined;
|
|
14
14
|
}>;
|
|
15
|
-
delegator
|
|
16
|
-
|
|
15
|
+
delegator({ request }: {
|
|
16
|
+
request: any;
|
|
17
|
+
}): Promise<WalletObject<any>>;
|
|
18
|
+
delegation({ request }: {
|
|
19
|
+
request: any;
|
|
20
|
+
}): Promise<any>;
|
|
17
21
|
chainInfo: () => {
|
|
18
22
|
type: "arcblock" | "ethereum" | "solona";
|
|
19
23
|
id: string;
|
package/lib/connect/shared.js
CHANGED
|
@@ -7,15 +7,19 @@ exports.getAuthenticatorProps = exports.getDelegatee = exports.getDelegator = ex
|
|
|
7
7
|
const url_join_1 = __importDefault(require("url-join"));
|
|
8
8
|
const jwt_1 = require("@arcblock/jwt");
|
|
9
9
|
const util_1 = require("@blocklet/meta/lib/util");
|
|
10
|
+
const wallet_1 = require("@ocap/wallet");
|
|
11
|
+
const constant_1 = require("@blocklet/constant");
|
|
12
|
+
const mcrypto_1 = require("@ocap/mcrypto");
|
|
13
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
10
14
|
const constants_1 = require("../util/constants");
|
|
11
|
-
const
|
|
15
|
+
const wallet_2 = __importDefault(require("../wallet"));
|
|
12
16
|
// wraps value in closure or returns closure
|
|
13
17
|
const closure = (value) => (typeof value === 'function' ? value : () => value);
|
|
14
18
|
const getDelegator = () => {
|
|
15
19
|
// BLOCKLET_WALLET_TYPE is for backward compatibility
|
|
16
20
|
const { BLOCKLET_APP_SK, BLOCKLET_APP_PSK, BLOCKLET_WALLET_TYPE, CHAIN_TYPE } = process.env;
|
|
17
21
|
if (BLOCKLET_APP_SK && BLOCKLET_APP_PSK && BLOCKLET_APP_SK !== BLOCKLET_APP_PSK) {
|
|
18
|
-
return (0,
|
|
22
|
+
return (0, wallet_2.default)(CHAIN_TYPE || BLOCKLET_WALLET_TYPE, BLOCKLET_APP_PSK);
|
|
19
23
|
}
|
|
20
24
|
return null;
|
|
21
25
|
};
|
|
@@ -23,7 +27,7 @@ exports.getDelegator = getDelegator;
|
|
|
23
27
|
const getDelegatee = () => {
|
|
24
28
|
// BLOCKLET_WALLET_TYPE is for backward compatibility
|
|
25
29
|
const { BLOCKLET_APP_SK, BLOCKLET_WALLET_TYPE, CHAIN_TYPE } = process.env;
|
|
26
|
-
return (0,
|
|
30
|
+
return (0, wallet_2.default)(CHAIN_TYPE || BLOCKLET_WALLET_TYPE, BLOCKLET_APP_SK);
|
|
27
31
|
};
|
|
28
32
|
exports.getDelegatee = getDelegatee;
|
|
29
33
|
const getDelegation = (delegator, delegatee) => {
|
|
@@ -49,6 +53,9 @@ const getDelegation = (delegator, delegatee) => {
|
|
|
49
53
|
});
|
|
50
54
|
};
|
|
51
55
|
exports.getDelegation = getDelegation;
|
|
56
|
+
function getProvider(request) {
|
|
57
|
+
return request.headers['x-user-provider'] || constant_1.LOGIN_PROVIDER.WALLET;
|
|
58
|
+
}
|
|
52
59
|
const getAuthenticatorProps = (options = {}) => ({
|
|
53
60
|
chainInfo: () => (0, util_1.getChainInfo)(process.env),
|
|
54
61
|
...options,
|
|
@@ -56,6 +63,12 @@ const getAuthenticatorProps = (options = {}) => ({
|
|
|
56
63
|
const info = await closure(options.appInfo)(...args);
|
|
57
64
|
const { request, baseUrl } = args[0];
|
|
58
65
|
const groupPathPrefix = request.headers['x-group-path-prefix'] || '/';
|
|
66
|
+
let agentDid;
|
|
67
|
+
const provider = getProvider(request);
|
|
68
|
+
// federated 登录模式下,需要告知原有的 blocklet-did
|
|
69
|
+
if (provider === constant_1.LOGIN_PROVIDER.FEDERATED) {
|
|
70
|
+
agentDid = process.env.BLOCKLET_DID;
|
|
71
|
+
}
|
|
59
72
|
return {
|
|
60
73
|
name: process.env.BLOCKLET_APP_NAME,
|
|
61
74
|
description: process.env.BLOCKLET_APP_DESCRIPTION,
|
|
@@ -65,13 +78,52 @@ const getAuthenticatorProps = (options = {}) => ({
|
|
|
65
78
|
updateSubEndpoint: true,
|
|
66
79
|
subscriptionEndpoint: (0, url_join_1.default)(groupPathPrefix, constants_1.SERVICE_PREFIX, 'websocket'),
|
|
67
80
|
nodeDid: process.env.ABT_NODE_DID,
|
|
81
|
+
agentDid,
|
|
68
82
|
};
|
|
69
83
|
},
|
|
70
|
-
delegator
|
|
84
|
+
async delegator({ request }) {
|
|
85
|
+
const provider = getProvider(request);
|
|
86
|
+
if (provider === constant_1.LOGIN_PROVIDER.FEDERATED) {
|
|
87
|
+
let blocklet;
|
|
88
|
+
try {
|
|
89
|
+
({ blocklet } = await this.authClient.getBlocklet());
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
throw new Error('failed to get blocklet');
|
|
93
|
+
}
|
|
94
|
+
const pk = (0, get_1.default)(blocklet, 'settings.federated.sites[0].pk');
|
|
95
|
+
if (pk) {
|
|
96
|
+
// NOTE: 这里的 type 参数必须保持跟生成 blocklet 时使用的是一致的
|
|
97
|
+
const type = {
|
|
98
|
+
role: mcrypto_1.types.RoleType.ROLE_APPLICATION,
|
|
99
|
+
pk: mcrypto_1.types.KeyType.ED25519,
|
|
100
|
+
hash: mcrypto_1.types.HashType.SHA3,
|
|
101
|
+
address: mcrypto_1.types.EncodingType.BASE58,
|
|
102
|
+
};
|
|
103
|
+
const delegator = (0, wallet_1.fromPublicKey)(pk, type);
|
|
104
|
+
return delegator;
|
|
105
|
+
}
|
|
106
|
+
throw new Error('federated login master-site pk not found');
|
|
107
|
+
}
|
|
71
108
|
const delegator = getDelegator();
|
|
72
109
|
return delegator;
|
|
73
110
|
},
|
|
74
|
-
delegation
|
|
111
|
+
async delegation({ request }) {
|
|
112
|
+
const provider = getProvider(request);
|
|
113
|
+
if (provider === constant_1.LOGIN_PROVIDER.FEDERATED) {
|
|
114
|
+
let blocklet;
|
|
115
|
+
try {
|
|
116
|
+
({ blocklet } = await this.authClient.getBlocklet());
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
throw new Error('failed to get blocklet');
|
|
120
|
+
}
|
|
121
|
+
const delegation = (0, get_1.default)(blocklet, 'settings.federated.config.delegation');
|
|
122
|
+
if (delegation) {
|
|
123
|
+
return delegation;
|
|
124
|
+
}
|
|
125
|
+
throw new Error('federated login master-site granted delegation not found');
|
|
126
|
+
}
|
|
75
127
|
const delegator = getDelegator();
|
|
76
128
|
if (delegator) {
|
|
77
129
|
const delegatee = getDelegatee();
|
package/lib/service/auth.d.ts
CHANGED
|
@@ -41,5 +41,6 @@ interface AuthService {
|
|
|
41
41
|
createPermission(args: OmitTeamDid<Client.RequestCreatePermissionInput>): Promise<Client.ResponsePermission>;
|
|
42
42
|
updatePermission(args: OmitTeamDid<Client.PermissionInput>): Promise<Client.ResponsePermission>;
|
|
43
43
|
deletePermission(name: string): Promise<Client.GeneralResponse>;
|
|
44
|
+
getBlocklet(attachRuntimeInfo: boolean): Promise<Client.ResponseBlocklet>;
|
|
44
45
|
}
|
|
45
46
|
export = AuthService;
|
package/lib/service/auth.js
CHANGED
|
@@ -12,6 +12,7 @@ const mcrypto_1 = require("@ocap/mcrypto");
|
|
|
12
12
|
const wallet_1 = require("@ocap/wallet");
|
|
13
13
|
const env_1 = require("@blocklet/env");
|
|
14
14
|
const constant_1 = __importDefault(require("@abtnode/constant"));
|
|
15
|
+
const constant_2 = require("@blocklet/constant");
|
|
15
16
|
const check_blocklet_env_1 = __importDefault(require("../util/check-blocklet-env"));
|
|
16
17
|
const version_1 = require("../version");
|
|
17
18
|
const wallet_2 = __importDefault(require("../wallet"));
|
|
@@ -100,6 +101,8 @@ class AuthService {
|
|
|
100
101
|
// disabled in current
|
|
101
102
|
// 'configTrustedPassports',
|
|
102
103
|
// 'configTrustedFactories',
|
|
104
|
+
// blocklet
|
|
105
|
+
'getBlocklet',
|
|
103
106
|
];
|
|
104
107
|
const teamDid = process.env.BLOCKLET_DID;
|
|
105
108
|
const apiFallback = (fn) => (params = {}, ...args) => fn({ input: { ...params, teamDid }, ...args });
|
|
@@ -129,6 +132,7 @@ class AuthService {
|
|
|
129
132
|
updatePermission: (fn) => (name, { description }) => fn({ input: { permission: (0, pickBy_1.default)({ name, description }, isNotNullOrUndefined), teamDid } }),
|
|
130
133
|
deletePermission: (fn) => (name) => fn({ input: { name, teamDid } }),
|
|
131
134
|
hasPermission: (fn) => (role, permission) => fn({ input: { teamDid, role, permission } }),
|
|
135
|
+
getBlocklet: (fn) => (attachRuntimeInfo = false) => fn({ input: { did: teamDid, attachRuntimeInfo } }),
|
|
132
136
|
};
|
|
133
137
|
apiList.forEach((api) => {
|
|
134
138
|
const fn = client[api];
|
|
@@ -159,6 +163,7 @@ class AuthService {
|
|
|
159
163
|
user: resData.user,
|
|
160
164
|
token: resData.nextToken,
|
|
161
165
|
refreshToken: resData?.nextRefreshToken,
|
|
166
|
+
provider: resData?.provider || constant_2.LOGIN_PROVIDER.WALLET,
|
|
162
167
|
};
|
|
163
168
|
}
|
|
164
169
|
catch (err) {
|
|
@@ -6,6 +6,7 @@ const did_auth_1 = require("@arcblock/did-auth");
|
|
|
6
6
|
const wallet_1 = __importDefault(require("./wallet"));
|
|
7
7
|
const check_blocklet_env_1 = __importDefault(require("./util/check-blocklet-env"));
|
|
8
8
|
const shared_1 = require("./connect/shared");
|
|
9
|
+
const auth_1 = __importDefault(require("./service/auth"));
|
|
9
10
|
class WalletAuthenticator extends did_auth_1.WalletAuthenticator {
|
|
10
11
|
constructor(options = {}) {
|
|
11
12
|
(0, check_blocklet_env_1.default)();
|
|
@@ -13,6 +14,7 @@ class WalletAuthenticator extends did_auth_1.WalletAuthenticator {
|
|
|
13
14
|
wallet: (0, wallet_1.default)().toJSON(),
|
|
14
15
|
...(0, shared_1.getAuthenticatorProps)(options),
|
|
15
16
|
});
|
|
17
|
+
this.authClient = new auth_1.default();
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
module.exports = WalletAuthenticator;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.14-beta-
|
|
6
|
+
"version": "1.16.14-beta-dc99d0a2",
|
|
7
7
|
"description": "graphql client to read/write data on abt node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"typings": "lib/index.d.ts",
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@abtnode/client": "1.16.14-beta-
|
|
30
|
-
"@abtnode/constant": "1.16.14-beta-
|
|
29
|
+
"@abtnode/client": "1.16.14-beta-dc99d0a2",
|
|
30
|
+
"@abtnode/constant": "1.16.14-beta-dc99d0a2",
|
|
31
31
|
"@arcblock/did": "1.18.87",
|
|
32
32
|
"@arcblock/did-auth": "1.18.87",
|
|
33
33
|
"@arcblock/jwt": "1.18.87",
|
|
34
34
|
"@arcblock/ws": "1.18.87",
|
|
35
|
-
"@blocklet/constant": "1.16.14-beta-
|
|
36
|
-
"@blocklet/env": "1.16.14-beta-
|
|
37
|
-
"@blocklet/meta": "1.16.14-beta-
|
|
38
|
-
"@did-connect/authenticator": "^2.
|
|
39
|
-
"@did-connect/handler": "^2.
|
|
35
|
+
"@blocklet/constant": "1.16.14-beta-dc99d0a2",
|
|
36
|
+
"@blocklet/env": "1.16.14-beta-dc99d0a2",
|
|
37
|
+
"@blocklet/meta": "1.16.14-beta-dc99d0a2",
|
|
38
|
+
"@did-connect/authenticator": "^2.2.0",
|
|
39
|
+
"@did-connect/handler": "^2.2.0",
|
|
40
40
|
"@nedb/core": "^2.1.5",
|
|
41
41
|
"@ocap/mcrypto": "1.18.87",
|
|
42
42
|
"@ocap/wallet": "1.18.87",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"ts-node": "^10.9.1",
|
|
74
74
|
"typescript": "^5.0.4"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "a00766d660ede97e2036f3a785f4f5cfb2e6d870"
|
|
77
77
|
}
|