@blocklet/sdk 1.8.32 → 1.8.34
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/component/index.d.ts +35 -0
- package/lib/component/index.js +83 -80
- package/lib/config.d.ts +33 -0
- package/lib/config.js +10 -7
- package/lib/connect/authenticator.d.ts +5 -0
- package/lib/connect/authenticator.js +14 -15
- package/lib/connect/handler.d.ts +2 -0
- package/lib/connect/handler.js +91 -65
- package/lib/connect/shared.d.ts +13 -0
- package/lib/connect/shared.js +26 -31
- package/lib/database/index.d.ts +13 -0
- package/lib/database/index.js +52 -39
- package/lib/env.d.ts +12 -0
- package/lib/env.js +12 -9
- package/lib/error-handler.d.ts +0 -0
- package/lib/error-handler.js +5 -5
- package/lib/index.d.ts +51 -0
- package/lib/index.js +51 -40
- package/lib/middlewares/auth.d.ts +3 -0
- package/lib/middlewares/auth.js +52 -49
- package/lib/middlewares/component.d.ts +7 -0
- package/lib/middlewares/component.js +28 -24
- package/lib/middlewares/index.d.ts +20 -0
- package/lib/middlewares/index.js +16 -8
- package/lib/middlewares/user.d.ts +10 -0
- package/lib/middlewares/user.js +20 -10
- package/lib/security/index.d.ts +9 -0
- package/lib/security/index.js +22 -21
- package/lib/service/auth.d.ts +9 -0
- package/lib/service/auth.js +131 -165
- package/lib/service/notification.d.ts +44 -0
- package/lib/service/notification.js +149 -129
- package/lib/types/notification.d.ts +71 -0
- package/lib/types/notification.js +3 -0
- package/lib/util/check-blocklet-env.d.ts +2 -0
- package/lib/util/check-blocklet-env.js +20 -19
- package/lib/util/constants.d.ts +5 -0
- package/lib/util/constants.js +6 -2
- package/lib/util/send-notification.d.ts +25 -0
- package/lib/util/send-notification.js +118 -115
- package/lib/validators/index.d.ts +12 -0
- package/lib/validators/index.js +13 -7
- package/lib/validators/notification.d.ts +59 -0
- package/lib/validators/notification.js +127 -97
- package/lib/version.d.ts +6 -0
- package/lib/version.js +6 -0
- package/lib/wallet-authenticator.d.ts +5 -0
- package/lib/wallet-authenticator.js +13 -16
- package/lib/wallet-handler.d.ts +17 -0
- package/lib/wallet-handler.js +121 -88
- package/lib/wallet.d.ts +3 -0
- package/lib/wallet.js +9 -10
- package/package.json +40 -18
package/lib/wallet-handler.js
CHANGED
|
@@ -1,97 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
35
|
+
var t = {};
|
|
36
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
37
|
+
t[p] = s[p];
|
|
38
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
39
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
40
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
41
|
+
t[p[i]] = s[p[i]];
|
|
42
|
+
}
|
|
43
|
+
return t;
|
|
44
|
+
};
|
|
45
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
|
+
};
|
|
48
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
49
|
+
const did_auth_1 = require("@arcblock/did-auth");
|
|
50
|
+
const notification_1 = __importStar(require("./service/notification"));
|
|
5
51
|
const noop = () => ({});
|
|
6
|
-
|
|
7
52
|
const CONNECTED_DID_KEY = 'headers[x-connected-did]';
|
|
8
|
-
|
|
9
53
|
// whether app web page is in mobile DID wallet
|
|
10
54
|
const inMobileWallet = (didwallet) => {
|
|
11
|
-
|
|
55
|
+
return didwallet && ['ios', 'android'].includes(didwallet.os);
|
|
12
56
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (inMobileWallet(didwallet)) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return get(req, CONNECTED_DID_KEY);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
attach({ onStart = noop, ...opts }) {
|
|
48
|
-
const _onStart = async (params) => {
|
|
49
|
-
const extra = (await onStart(params)) || {};
|
|
50
|
-
|
|
51
|
-
const connectedDid = this.getConnectedDid(params);
|
|
52
|
-
|
|
53
|
-
// fill extra
|
|
54
|
-
extra.connectedDid = connectedDid || '';
|
|
55
|
-
extra.saveConnect = this.enableConnect;
|
|
56
|
-
|
|
57
|
-
// send notification to wallet to trigger wallet to auto connect
|
|
58
|
-
if (connectedDid) {
|
|
59
|
-
// wallet use check url to check status of the session
|
|
60
|
-
let checkUrl = '';
|
|
61
|
-
try {
|
|
62
|
-
checkUrl = new URL(decodeURIComponent(new URL(params.deepLink).searchParams.get('url')));
|
|
63
|
-
checkUrl.pathname = checkUrl.pathname.replace(/auth$/, 'status');
|
|
64
|
-
} catch (e) {
|
|
65
|
-
checkUrl = '';
|
|
66
|
-
console.error(e);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const message = {
|
|
70
|
-
type: 'connect',
|
|
71
|
-
url: params.deepLink,
|
|
57
|
+
class WalletHandlers extends did_auth_1.WalletHandlers {
|
|
58
|
+
/**
|
|
59
|
+
* @param {boolean} autoConnect enable auto connect to wallet (wallet does not need to scan qr code)
|
|
60
|
+
* @param {boolean} connectedDidOnly only current login did or connected did can connect
|
|
61
|
+
* @param {function} sendNotificationFn use in a non-blocklet environment
|
|
62
|
+
*/
|
|
63
|
+
constructor(_a) {
|
|
64
|
+
var { autoConnect = true, connectedDidOnly = false, sendNotificationFn, options = {} } = _a, opts = __rest(_a, ["autoConnect", "connectedDidOnly", "sendNotificationFn", "options"]);
|
|
65
|
+
// FIXME: wait check
|
|
66
|
+
// if (autoConnect && connectedDidOnly) {
|
|
67
|
+
// options.sessionDidKey = CONNECTED_DID_KEY;
|
|
68
|
+
// }
|
|
69
|
+
super(Object.assign({ options: Object.assign(Object.assign({}, options), {
|
|
70
|
+
sessionDidKey: autoConnect && connectedDidOnly ? CONNECTED_DID_KEY : options === null || options === void 0 ? void 0 : options.sessionDidKey,
|
|
71
|
+
}) }, opts));
|
|
72
|
+
this.getConnectedDid = ({ req, didwallet, extraParams }) => {
|
|
73
|
+
if (extraParams && extraParams.autoConnect === 'false') {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
if (!this.enableConnect) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
if (inMobileWallet(didwallet)) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return (0, get_1.default)(req, CONNECTED_DID_KEY);
|
|
72
83
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
this.enableConnect = !!autoConnect;
|
|
85
|
+
this.sendNotificationFn = sendNotificationFn || notification_1.sendToUser.bind(notification_1.default);
|
|
86
|
+
}
|
|
87
|
+
attach(_a) {
|
|
88
|
+
var { onStart = noop } = _a, opts = __rest(_a, ["onStart"]);
|
|
89
|
+
const realOnStart = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
// @ts-expect-error TS(2554) FIXME: Expected 0 arguments, but got 1.
|
|
91
|
+
const extra = (yield onStart(params)) || {};
|
|
92
|
+
const connectedDid = this.getConnectedDid(params);
|
|
93
|
+
// fill extra
|
|
94
|
+
extra.connectedDid = connectedDid || '';
|
|
95
|
+
extra.saveConnect = this.enableConnect;
|
|
96
|
+
// send notification to wallet to trigger wallet to auto connect
|
|
97
|
+
if (connectedDid) {
|
|
98
|
+
// wallet use check url to check status of the session
|
|
99
|
+
let checkUrl = '';
|
|
100
|
+
try {
|
|
101
|
+
// @ts-expect-error TS(2322) FIXME: Type 'URL' is not assignable to type 'string'.
|
|
102
|
+
checkUrl = new URL(decodeURIComponent(new URL(params.deepLink).searchParams.get('url')));
|
|
103
|
+
checkUrl.pathname = checkUrl.pathname.replace(/auth$/, 'status');
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
checkUrl = '';
|
|
107
|
+
console.error(e);
|
|
108
|
+
}
|
|
109
|
+
const message = {
|
|
110
|
+
type: 'connect',
|
|
111
|
+
url: params.deepLink,
|
|
112
|
+
};
|
|
113
|
+
if (checkUrl) {
|
|
114
|
+
message.checkUrl = checkUrl.href;
|
|
115
|
+
}
|
|
116
|
+
// sendNotificationFn maybe custom function so we need params
|
|
117
|
+
this.sendNotificationFn(connectedDid, message, params).catch((err) => {
|
|
118
|
+
console.error(err);
|
|
119
|
+
if (typeof opts.onError === 'function') {
|
|
120
|
+
opts.onError(err);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return extra;
|
|
84
125
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
super.attach({
|
|
91
|
-
onStart: _onStart,
|
|
92
|
-
...opts,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
126
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{ onStart: (params: any) => Prom... Remove this comment to see the full error message
|
|
127
|
+
super.attach(Object.assign({ onStart: realOnStart }, opts));
|
|
128
|
+
}
|
|
95
129
|
}
|
|
96
|
-
|
|
97
130
|
module.exports = WalletHandlers;
|
package/lib/wallet.d.ts
ADDED
package/lib/wallet.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return fromSecretKey(process.env.BLOCKLET_APP_SK, type);
|
|
1
|
+
"use strict";
|
|
2
|
+
const wallet_1 = require("@ocap/wallet");
|
|
3
|
+
const mcrypto_1 = require("@ocap/mcrypto");
|
|
4
|
+
const getWallet = () => {
|
|
5
|
+
const type = process.env.BLOCKLET_WALLET_TYPE !== 'eth'
|
|
6
|
+
? (0, wallet_1.WalletType)({ role: mcrypto_1.types.RoleType.ROLE_APPLICATION, pk: mcrypto_1.types.KeyType.ED25519, hash: mcrypto_1.types.HashType.SHA3 })
|
|
7
|
+
: 'eth';
|
|
8
|
+
return (0, wallet_1.fromSecretKey)(process.env.BLOCKLET_APP_SK, type);
|
|
11
9
|
};
|
|
10
|
+
module.exports = getWallet;
|
package/package.json
CHANGED
|
@@ -3,34 +3,41 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.34",
|
|
7
7
|
"description": "graphql client to read/write data on abt node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
|
+
"typings": "lib/index.d.ts",
|
|
9
10
|
"files": [
|
|
10
11
|
"lib",
|
|
11
12
|
"service"
|
|
12
13
|
],
|
|
13
14
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
-
"lint
|
|
16
|
-
"
|
|
17
|
-
"
|
|
15
|
+
"verify": "npm run lint:fix && npm run test && npm run build",
|
|
16
|
+
"lint": "eslint src tests service",
|
|
17
|
+
"lint:fix": "npm run lint -- --fix",
|
|
18
|
+
"test": "jest --forceExit --detectOpenHandles",
|
|
19
|
+
"coverage": "npm run test -- --coverage",
|
|
20
|
+
"clean": "rm -fr lib",
|
|
21
|
+
"prebuild": "npm run clean && npm run types",
|
|
22
|
+
"types": "rm -rf ./src/types && node tools/version.js && ts-node tools/types.js && rm -f ./src/types/index.ts && prettier --write ./src/types/notification.ts",
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"build:watch": "npm run build -- -w"
|
|
18
25
|
},
|
|
19
26
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
20
27
|
"license": "MIT",
|
|
21
28
|
"dependencies": {
|
|
22
|
-
"@abtnode/client": "1.8.
|
|
23
|
-
"@abtnode/constant": "1.8.
|
|
24
|
-
"@arcblock/did-auth": "1.18.
|
|
25
|
-
"@arcblock/jwt": "1.18.
|
|
26
|
-
"@arcblock/ws": "1.18.
|
|
27
|
-
"@blocklet/constant": "1.8.
|
|
28
|
-
"@blocklet/meta": "1.8.
|
|
29
|
-
"@did-connect/authenticator": "^2.1.
|
|
30
|
-
"@did-connect/handler": "^2.1.
|
|
29
|
+
"@abtnode/client": "1.8.34",
|
|
30
|
+
"@abtnode/constant": "1.8.34",
|
|
31
|
+
"@arcblock/did-auth": "1.18.13",
|
|
32
|
+
"@arcblock/jwt": "1.18.13",
|
|
33
|
+
"@arcblock/ws": "1.18.13",
|
|
34
|
+
"@blocklet/constant": "1.8.34",
|
|
35
|
+
"@blocklet/meta": "1.8.34",
|
|
36
|
+
"@did-connect/authenticator": "^2.1.26",
|
|
37
|
+
"@did-connect/handler": "^2.1.26",
|
|
31
38
|
"@nedb/core": "^2.0.5",
|
|
32
|
-
"@ocap/mcrypto": "1.18.
|
|
33
|
-
"@ocap/wallet": "1.18.
|
|
39
|
+
"@ocap/mcrypto": "1.18.13",
|
|
40
|
+
"@ocap/wallet": "1.18.13",
|
|
34
41
|
"axios": "^0.27.2",
|
|
35
42
|
"fs-extra": "^10.1.0",
|
|
36
43
|
"joi": "17.6.3",
|
|
@@ -43,8 +50,23 @@
|
|
|
43
50
|
"@nedb/core": "^2.0.5"
|
|
44
51
|
},
|
|
45
52
|
"devDependencies": {
|
|
53
|
+
"@arcblock/eslint-config-ts": "^0.2.3",
|
|
54
|
+
"@types/express": "^4.17.14",
|
|
55
|
+
"@types/jest": "^29.2.0",
|
|
56
|
+
"@types/json-stable-stringify": "^1.0.34",
|
|
57
|
+
"@types/lodash": "^4.14.186",
|
|
58
|
+
"@types/node": "^18.11.0",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^5.40.1",
|
|
60
|
+
"@typescript-eslint/parser": "^5.40.1",
|
|
46
61
|
"detect-port": "^1.5.1",
|
|
47
|
-
"
|
|
62
|
+
"eslint": "^8.25.0",
|
|
63
|
+
"jest": "^29.2.0",
|
|
64
|
+
"joi-to-typescript": "^4.0.6",
|
|
65
|
+
"json-stable-stringify": "^1.0.1",
|
|
66
|
+
"prettier": "^2.7.1",
|
|
67
|
+
"ts-jest": "^29.0.3",
|
|
68
|
+
"ts-node": "^10.9.1",
|
|
69
|
+
"typescript": "^4.8.4"
|
|
48
70
|
},
|
|
49
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "c5fbb8e57493db62f212217cfde1980c82f00297"
|
|
50
72
|
}
|