@arcblock/did-connect-js 1.29.23 → 4.0.0-beta.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.
Files changed (118) hide show
  1. package/{lib/adapters/detect.d.cts → dist/adapters/detect.d.ts} +3 -5
  2. package/dist/adapters/detect.d.ts.map +1 -0
  3. package/dist/adapters/detect.js +13 -0
  4. package/dist/adapters/detect.js.map +1 -0
  5. package/dist/adapters/express.d.ts +40 -0
  6. package/dist/adapters/express.d.ts.map +1 -0
  7. package/dist/adapters/express.js +30 -0
  8. package/dist/adapters/express.js.map +1 -0
  9. package/dist/adapters/hono.d.ts +49 -0
  10. package/dist/adapters/hono.d.ts.map +1 -0
  11. package/dist/adapters/hono.js +176 -0
  12. package/dist/adapters/hono.js.map +1 -0
  13. package/dist/authenticator/base.d.ts +21 -0
  14. package/dist/authenticator/base.d.ts.map +1 -0
  15. package/dist/authenticator/base.js +109 -0
  16. package/dist/authenticator/base.js.map +1 -0
  17. package/dist/authenticator/wallet.d.ts +221 -0
  18. package/dist/authenticator/wallet.d.ts.map +1 -0
  19. package/dist/authenticator/wallet.js +588 -0
  20. package/dist/authenticator/wallet.js.map +1 -0
  21. package/dist/handlers/base.d.ts +25 -0
  22. package/dist/handlers/base.d.ts.map +1 -0
  23. package/dist/handlers/base.js +48 -0
  24. package/dist/handlers/base.js.map +1 -0
  25. package/dist/handlers/util.d.ts +48 -0
  26. package/dist/handlers/util.d.ts.map +1 -0
  27. package/dist/handlers/util.js +812 -0
  28. package/dist/handlers/util.js.map +1 -0
  29. package/dist/handlers/wallet.d.ts +96 -0
  30. package/dist/handlers/wallet.d.ts.map +1 -0
  31. package/dist/handlers/wallet.js +129 -0
  32. package/dist/handlers/wallet.js.map +1 -0
  33. package/dist/index.d.ts +10 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +9 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/protocol.d.ts +14 -0
  38. package/dist/protocol.d.ts.map +1 -0
  39. package/dist/protocol.js +37 -0
  40. package/dist/protocol.js.map +1 -0
  41. package/dist/schema/claims.d.ts +17 -0
  42. package/dist/schema/claims.d.ts.map +1 -0
  43. package/dist/schema/claims.js +205 -0
  44. package/dist/schema/claims.js.map +1 -0
  45. package/dist/schema/index.d.ts +7 -0
  46. package/dist/schema/index.d.ts.map +1 -0
  47. package/dist/schema/index.js +49 -0
  48. package/dist/schema/index.js.map +1 -0
  49. package/dist/storage/kv.d.ts +31 -0
  50. package/dist/storage/kv.d.ts.map +1 -0
  51. package/dist/storage/kv.js +54 -0
  52. package/dist/storage/kv.js.map +1 -0
  53. package/dist/types.d.ts +53 -0
  54. package/dist/types.d.ts.map +1 -0
  55. package/dist/types.js +2 -0
  56. package/dist/types.js.map +1 -0
  57. package/package.json +48 -104
  58. package/LICENSE +0 -13
  59. package/README.md +0 -210
  60. package/esm/_virtual/rolldown_runtime.mjs +0 -8
  61. package/esm/adapters/detect.d.mts +0 -11
  62. package/esm/adapters/detect.mjs +0 -16
  63. package/esm/adapters/express.d.mts +0 -48
  64. package/esm/adapters/express.mjs +0 -39
  65. package/esm/adapters/hono.d.mts +0 -57
  66. package/esm/adapters/hono.mjs +0 -164
  67. package/esm/authenticator/base.d.mts +0 -23
  68. package/esm/authenticator/base.mjs +0 -88
  69. package/esm/authenticator/wallet.d.mts +0 -270
  70. package/esm/authenticator/wallet.mjs +0 -556
  71. package/esm/handlers/base.d.mts +0 -32
  72. package/esm/handlers/base.mjs +0 -37
  73. package/esm/handlers/util.d.mts +0 -70
  74. package/esm/handlers/util.mjs +0 -739
  75. package/esm/handlers/wallet.d.mts +0 -120
  76. package/esm/handlers/wallet.mjs +0 -139
  77. package/esm/index.d.mts +0 -8
  78. package/esm/index.mjs +0 -8
  79. package/esm/package.mjs +0 -118
  80. package/esm/protocol.d.mts +0 -15
  81. package/esm/protocol.mjs +0 -40
  82. package/esm/schema/claims.d.mts +0 -18
  83. package/esm/schema/claims.mjs +0 -154
  84. package/esm/schema/index.d.mts +0 -9
  85. package/esm/schema/index.mjs +0 -49
  86. package/esm/storage/kv.d.mts +0 -33
  87. package/esm/storage/kv.mjs +0 -55
  88. package/esm/types.d.mts +0 -55
  89. package/esm/types.mjs +0 -1
  90. package/lib/_virtual/rolldown_runtime.cjs +0 -31
  91. package/lib/adapters/detect.cjs +0 -18
  92. package/lib/adapters/express.cjs +0 -41
  93. package/lib/adapters/express.d.cts +0 -48
  94. package/lib/adapters/hono.cjs +0 -167
  95. package/lib/adapters/hono.d.cts +0 -57
  96. package/lib/authenticator/base.cjs +0 -91
  97. package/lib/authenticator/base.d.cts +0 -23
  98. package/lib/authenticator/wallet.cjs +0 -564
  99. package/lib/authenticator/wallet.d.cts +0 -270
  100. package/lib/handlers/base.cjs +0 -40
  101. package/lib/handlers/base.d.cts +0 -32
  102. package/lib/handlers/util.cjs +0 -759
  103. package/lib/handlers/util.d.cts +0 -70
  104. package/lib/handlers/wallet.cjs +0 -139
  105. package/lib/handlers/wallet.d.cts +0 -119
  106. package/lib/index.cjs +0 -16
  107. package/lib/index.d.cts +0 -8
  108. package/lib/package.cjs +0 -121
  109. package/lib/protocol.cjs +0 -46
  110. package/lib/protocol.d.cts +0 -15
  111. package/lib/schema/claims.cjs +0 -156
  112. package/lib/schema/claims.d.cts +0 -18
  113. package/lib/schema/index.cjs +0 -52
  114. package/lib/schema/index.d.cts +0 -9
  115. package/lib/storage/kv.cjs +0 -57
  116. package/lib/storage/kv.d.cts +0 -33
  117. package/lib/types.cjs +0 -0
  118. package/lib/types.d.cts +0 -55
@@ -1,70 +0,0 @@
1
- import { ConnectRequest, ConnectResponse, NextFunction } from "../types.cjs";
2
-
3
- //#region src/handlers/util.d.ts
4
- declare const errors: Record<string, Record<string, string>>;
5
- declare const preparePathname: (path: string, req: ConnectRequest) => string;
6
- declare const prepareBaseUrl: (req: ConnectRequest, params?: Record<string, any>) => string;
7
- declare const getStepChallenge: () => any;
8
- declare const parseWalletUA: (userAgent: string) => {
9
- os: string;
10
- version: string;
11
- jwt: string;
12
- };
13
- declare const isDeepLink: (str: string) => boolean;
14
- declare const isConnectedOnly: (params: any, sessionUserDid?: string) => boolean | string;
15
- interface CreateHandlersOptions {
16
- action: string;
17
- pathname: string;
18
- claims: any;
19
- onStart: (...args: any[]) => any;
20
- onConnect: (...args: any[]) => any;
21
- onAuth: (...args: any[]) => any;
22
- onDecline: (...args: any[]) => any;
23
- onComplete: (...args: any[]) => any;
24
- onExpire: (...args: any[]) => any;
25
- onError: (...args: any[]) => any;
26
- pathTransformer: (v: string) => string;
27
- tokenStorage: any;
28
- authenticator: any;
29
- authPrincipal: any;
30
- persistentDynamicClaims?: boolean;
31
- getSignParams?: (req: ConnectRequest) => any;
32
- getPathName?: (pathname: string, req: ConnectRequest) => string;
33
- options: {
34
- tokenKey: string;
35
- encKey: string;
36
- versionKey: string;
37
- cleanupDelay: number;
38
- };
39
- }
40
- declare function createHandlers({
41
- action,
42
- pathname,
43
- claims,
44
- onStart,
45
- onConnect,
46
- onAuth,
47
- onDecline,
48
- onComplete,
49
- onExpire,
50
- onError,
51
- pathTransformer,
52
- tokenStorage,
53
- authenticator,
54
- authPrincipal,
55
- persistentDynamicClaims,
56
- getSignParams,
57
- getPathName,
58
- options
59
- }: CreateHandlersOptions): {
60
- generateSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
61
- expireSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
62
- checkSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
63
- onAuthRequest: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
64
- onAuthResponse: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
65
- ensureContext: (req: ConnectRequest, _res: ConnectResponse, next: NextFunction) => Promise<void>;
66
- ensureSignedJson: (req: ConnectRequest, res: ConnectResponse, next: NextFunction) => void;
67
- createExtraParams: (locale: string, params: any, extra?: any) => any;
68
- };
69
- //#endregion
70
- export { CreateHandlersOptions, createHandlers as default, errors, getStepChallenge, isConnectedOnly, isDeepLink, parseWalletUA, prepareBaseUrl, preparePathname };
@@ -1,139 +0,0 @@
1
- Object.defineProperty(exports, '__esModule', { value: true });
2
- const require_package$1 = require('../package.cjs');
3
- const require_adapters_detect = require('../adapters/detect.cjs');
4
- const require_adapters_express = require('../adapters/express.cjs');
5
- const require_adapters_hono = require('../adapters/hono.cjs');
6
- const require_handlers_base = require('./base.cjs');
7
- const require_handlers_util = require('./util.cjs');
8
-
9
- //#region src/handlers/wallet.ts
10
- const debug = require("debug")(`${require_package$1.default.name}:handlers:wallet`);
11
- const noop = () => {};
12
- /**
13
- * Events that are emitted during an DID Connect process
14
- *
15
- * - scanned: when the qrcode is scanned by wallet
16
- * - succeed: when authentication complete
17
- * - error: when something goes wrong
18
- *
19
- * @class WalletHandlers
20
- * @extends {EventEmitter}
21
- */
22
- var WalletHandlers = class extends require_handlers_base.default {
23
- /**
24
- * Creates an instance of DID Auth Handlers.
25
- *
26
- * @class
27
- * @param {object} config
28
- * @param {object} config.tokenStorage - function to generate action token
29
- * @param {object} config.authenticator - Authenticator instance that can to jwt sign/verify
30
- * @param {function} [config.pathTransformer=null] - how should we update pathname
31
- * @param {function} [config.onConnect=noop] - function called before each auth request send back to app, used to check for permission, throw error to halt the auth process
32
- * @param {object} [config.options={}] - custom options to define all handlers attached
33
- * @param {string} [config.options.prefix='/api/did'] - url prefix for this group endpoints
34
- * @param {number} [config.options.cleanupDelay=60000] - how long to wait before cleanup finished session
35
- * @param {string} [config.options.tokenKey='_t_'] - query param key for `token`
36
- * @param {string} [config.options.encKey='_ek_'] - query param key for encryption key
37
- * @param {string} [config.options.versionKey='_v_'] - query param key for protocol `version`
38
- */
39
- constructor({ pathTransformer, tokenStorage, authenticator, onConnect = noop, options = {} }) {
40
- super({
41
- pathTransformer,
42
- tokenStorage,
43
- authenticator,
44
- onConnect
45
- });
46
- this.options = {
47
- prefix: "/api/did",
48
- cleanupDelay: 6e4,
49
- tokenKey: "_t_",
50
- encKey: "_ek_",
51
- versionKey: "_v_",
52
- ...options
53
- };
54
- }
55
- /**
56
- * Attach routes and handlers for authenticator
57
- * Now express app have route handlers attached to the following url
58
- * - `GET /api/did/{action}/token` create new token
59
- * - `GET /api/did/{action}/status` check for token status
60
- * - `GET /api/did/{action}/timeout` expire a token
61
- * - `GET /api/did/{action}/auth` create auth response
62
- * - `POST /api/did/{action}/auth` process payment request
63
- *
64
- * @method
65
- * @param {object} config
66
- * @param {object} config.app - express instance to attach routes to
67
- * @param {object} [config.claims] - claims for this request
68
- * @param {string} config.action - action of this group of routes
69
- * @param {function} [config.onStart=noop] - callback when a new action start
70
- * @param {function} [config.onConnect=noop] - callback when a new action start
71
- * @param {function} config.onAuth - callback when user completed auth in DID Wallet, and data posted back
72
- * @param {function} [config.onDecline=noop] - callback when user has declined in wallet
73
- * @param {function} [config.onComplete=noop] - callback when the whole auth process is done, action token is removed
74
- * @param {function} [config.onExpire=noop] - callback when the action token expired
75
- * @param {function} [config.onError=console.error] - callback when there are some errors
76
- * @param {boolean|string|did} [config.authPrincipal=true] - whether should we do auth principal claim first
77
- * @param {boolean} [config.persistentDynamicClaims=false] - whether should we persist dynamic claims
78
- * @return void
79
- */
80
- attach({ app, action, claims = void 0, onStart = noop, onConnect, onAuth, onDecline = noop, onComplete = noop, onExpire = noop, onError = console.error, authPrincipal = true, persistentDynamicClaims = false }) {
81
- if (typeof onAuth !== "function") throw new Error("onAuth callback is required to attach did auth handlers");
82
- if (typeof onDecline !== "function") throw new Error("onDecline callback is required to attach did auth handlers");
83
- if (typeof onComplete !== "function") throw new Error("onComplete callback is required to attach did auth handlers");
84
- const { prefix } = this.options;
85
- const pathname = `${prefix}/${action}/auth`;
86
- debug("attach routes", {
87
- action,
88
- prefix,
89
- pathname
90
- });
91
- const onConnectWrapped = async (...args) => {
92
- if (typeof this.onConnect === "function") await this.onConnect(...args);
93
- if (typeof onConnect === "function") return onConnect(...args);
94
- };
95
- const { generateSession, expireSession, checkSession, onAuthRequest, onAuthResponse, ensureContext, ensureSignedJson } = require_handlers_util.default({
96
- action,
97
- pathname,
98
- claims,
99
- onStart,
100
- onConnect: onConnectWrapped,
101
- onAuth,
102
- onDecline,
103
- onComplete,
104
- onExpire,
105
- onError,
106
- authPrincipal,
107
- persistentDynamicClaims,
108
- options: this.options,
109
- pathTransformer: this.pathTransformer,
110
- tokenStorage: this.tokenStorage,
111
- authenticator: this.authenticator
112
- });
113
- const handlerFns = {
114
- generateSession,
115
- checkSession,
116
- expireSession,
117
- onAuthRequest,
118
- onAuthResponse,
119
- ensureContext,
120
- ensureSignedJson
121
- };
122
- if (require_adapters_detect.isHonoApp(app)) return require_adapters_hono.attachHono({
123
- app,
124
- prefix,
125
- action,
126
- handlers: handlerFns
127
- });
128
- return require_adapters_express.attachExpress({
129
- app,
130
- prefix,
131
- action,
132
- handlers: handlerFns
133
- });
134
- }
135
- };
136
- var wallet_default = WalletHandlers;
137
-
138
- //#endregion
139
- exports.default = wallet_default;
@@ -1,119 +0,0 @@
1
- import { ConnectRequest, ConnectResponse } from "../types.cjs";
2
- import BaseHandler from "./base.cjs";
3
-
4
- //#region src/handlers/wallet.d.ts
5
-
6
- /**
7
- * Events that are emitted during an DID Connect process
8
- *
9
- * - scanned: when the qrcode is scanned by wallet
10
- * - succeed: when authentication complete
11
- * - error: when something goes wrong
12
- *
13
- * @class WalletHandlers
14
- * @extends {EventEmitter}
15
- */
16
- declare class WalletHandlers extends BaseHandler {
17
- options: {
18
- prefix: string;
19
- cleanupDelay: number;
20
- tokenKey: string;
21
- encKey: string;
22
- versionKey: string;
23
- };
24
- /**
25
- * Creates an instance of DID Auth Handlers.
26
- *
27
- * @class
28
- * @param {object} config
29
- * @param {object} config.tokenStorage - function to generate action token
30
- * @param {object} config.authenticator - Authenticator instance that can to jwt sign/verify
31
- * @param {function} [config.pathTransformer=null] - how should we update pathname
32
- * @param {function} [config.onConnect=noop] - function called before each auth request send back to app, used to check for permission, throw error to halt the auth process
33
- * @param {object} [config.options={}] - custom options to define all handlers attached
34
- * @param {string} [config.options.prefix='/api/did'] - url prefix for this group endpoints
35
- * @param {number} [config.options.cleanupDelay=60000] - how long to wait before cleanup finished session
36
- * @param {string} [config.options.tokenKey='_t_'] - query param key for `token`
37
- * @param {string} [config.options.encKey='_ek_'] - query param key for encryption key
38
- * @param {string} [config.options.versionKey='_v_'] - query param key for protocol `version`
39
- */
40
- constructor({
41
- pathTransformer,
42
- tokenStorage,
43
- authenticator,
44
- onConnect,
45
- options
46
- }: {
47
- pathTransformer?: (v: string) => string;
48
- tokenStorage: any;
49
- authenticator: any;
50
- onConnect?: (...args: any[]) => any;
51
- options?: Partial<{
52
- prefix: string;
53
- cleanupDelay: number;
54
- tokenKey: string;
55
- encKey: string;
56
- versionKey: string;
57
- }>;
58
- });
59
- /**
60
- * Attach routes and handlers for authenticator
61
- * Now express app have route handlers attached to the following url
62
- * - `GET /api/did/{action}/token` create new token
63
- * - `GET /api/did/{action}/status` check for token status
64
- * - `GET /api/did/{action}/timeout` expire a token
65
- * - `GET /api/did/{action}/auth` create auth response
66
- * - `POST /api/did/{action}/auth` process payment request
67
- *
68
- * @method
69
- * @param {object} config
70
- * @param {object} config.app - express instance to attach routes to
71
- * @param {object} [config.claims] - claims for this request
72
- * @param {string} config.action - action of this group of routes
73
- * @param {function} [config.onStart=noop] - callback when a new action start
74
- * @param {function} [config.onConnect=noop] - callback when a new action start
75
- * @param {function} config.onAuth - callback when user completed auth in DID Wallet, and data posted back
76
- * @param {function} [config.onDecline=noop] - callback when user has declined in wallet
77
- * @param {function} [config.onComplete=noop] - callback when the whole auth process is done, action token is removed
78
- * @param {function} [config.onExpire=noop] - callback when the action token expired
79
- * @param {function} [config.onError=console.error] - callback when there are some errors
80
- * @param {boolean|string|did} [config.authPrincipal=true] - whether should we do auth principal claim first
81
- * @param {boolean} [config.persistentDynamicClaims=false] - whether should we persist dynamic claims
82
- * @return void
83
- */
84
- attach({
85
- app,
86
- action,
87
- claims,
88
- onStart,
89
- onConnect,
90
- onAuth,
91
- onDecline,
92
- onComplete,
93
- onExpire,
94
- onError,
95
- authPrincipal,
96
- persistentDynamicClaims
97
- }: {
98
- app: any;
99
- action: string;
100
- claims?: any;
101
- onStart?: (...args: any[]) => any;
102
- onConnect?: (...args: any[]) => any;
103
- onAuth: (...args: any[]) => any;
104
- onDecline?: (...args: any[]) => any;
105
- onComplete?: (...args: any[]) => any;
106
- onExpire?: (...args: any[]) => any;
107
- onError?: (...args: any[]) => any;
108
- authPrincipal?: boolean | string | any;
109
- persistentDynamicClaims?: boolean;
110
- }): {
111
- generateSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
112
- expireSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
113
- checkSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
114
- onAuthRequest: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
115
- onAuthResponse: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
116
- };
117
- }
118
- //#endregion
119
- export { WalletHandlers as default };
package/lib/index.cjs DELETED
@@ -1,16 +0,0 @@
1
- const require_authenticator_wallet = require('./authenticator/wallet.cjs');
2
- const require_adapters_detect = require('./adapters/detect.cjs');
3
- const require_adapters_express = require('./adapters/express.cjs');
4
- const require_adapters_hono = require('./adapters/hono.cjs');
5
- const require_handlers_wallet = require('./handlers/wallet.cjs');
6
- const require_storage_kv = require('./storage/kv.cjs');
7
-
8
- exports.CloudflareKVStorage = require_storage_kv.default;
9
- exports.WalletAuthenticator = require_authenticator_wallet.default;
10
- exports.WalletHandlers = require_handlers_wallet.default;
11
- exports.attachExpress = require_adapters_express.attachExpress;
12
- exports.attachHono = require_adapters_hono.attachHono;
13
- exports.createHonoRequest = require_adapters_hono.createHonoRequest;
14
- exports.createHonoResponse = require_adapters_hono.createHonoResponse;
15
- exports.isExpressApp = require_adapters_detect.isExpressApp;
16
- exports.isHonoApp = require_adapters_detect.isHonoApp;
package/lib/index.d.cts DELETED
@@ -1,8 +0,0 @@
1
- import { isExpressApp, isHonoApp } from "./adapters/detect.cjs";
2
- import { ConnectRequest, ConnectResponse, NextFunction } from "./types.cjs";
3
- import { attachExpress } from "./adapters/express.cjs";
4
- import { attachHono, createHonoRequest, createHonoResponse } from "./adapters/hono.cjs";
5
- import WalletAuthenticator from "./authenticator/wallet.cjs";
6
- import CloudflareKVStorage from "./storage/kv.cjs";
7
- import WalletHandlers from "./handlers/wallet.cjs";
8
- export { CloudflareKVStorage, type ConnectRequest, type ConnectResponse, type NextFunction, WalletAuthenticator, WalletHandlers, attachExpress, attachHono, createHonoRequest, createHonoResponse, isExpressApp, isHonoApp };
package/lib/package.cjs DELETED
@@ -1,121 +0,0 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
-
3
- //#region package.json
4
- var require_package = /* @__PURE__ */ require_rolldown_runtime.__commonJSMin(((exports, module) => {
5
- module.exports = {
6
- "name": "@arcblock/did-connect-js",
7
- "description": "Helper function to setup DID Connect support on a node.js web server",
8
- "type": "module",
9
- "version": "1.20.2",
10
- "author": {
11
- "name": "wangshijun",
12
- "email": "shijun@arcblock.io",
13
- "url": "https://github.com/wangshijun"
14
- },
15
- "contributors": ["wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"],
16
- "bugs": {
17
- "url": "https://github.com/ArcBlock/blockchain/issues",
18
- "email": "shijun@arcblock.io"
19
- },
20
- "publishConfig": { "access": "public" },
21
- "dependencies": {
22
- "@arcblock/did": "workspace:*",
23
- "@arcblock/jwt": "workspace:*",
24
- "@arcblock/validator": "workspace:*",
25
- "@ocap/client": "workspace:*",
26
- "@ocap/mcrypto": "workspace:*",
27
- "@ocap/util": "workspace:*",
28
- "@ocap/wallet": "workspace:*",
29
- "cors": "^2.8.5",
30
- "debug": "^4.4.3",
31
- "json-stable-stringify": "^1.0.1",
32
- "lodash": "^4.17.23",
33
- "tweetnacl-sealedbox-js": "^1.2.0"
34
- },
35
- "devDependencies": {
36
- "@arcblock/did-agent-storage-memory": "^1.8.0",
37
- "@arcblock/did-connect-storage-memory": "^1.8.0",
38
- "@ocap/e2e-test": "workspace:*",
39
- "@types/cors": "^2.8.17",
40
- "@types/debug": "^4.1.12",
41
- "@types/json-stable-stringify": "^1.0.36",
42
- "@types/lodash": "^4.17.13",
43
- "@types/node": "^22.7.5",
44
- "axios": "^1.13.4",
45
- "remark-cli": "^10.0.1",
46
- "remark-preset-github": "^4.0.4",
47
- "hono": "^4.7.0",
48
- "tsdown": "^0.18.4",
49
- "tweetnacl": "^1.0.3"
50
- },
51
- "remarkConfig": { "plugins": ["preset-github", [{ "repository": "ArcBlock/blockchain" }]] },
52
- "homepage": "https://www.arcblock.io/docs/did-connect-sdk",
53
- "keywords": [
54
- "blockchain",
55
- "arcblock",
56
- "sdk",
57
- "nodejs"
58
- ],
59
- "license": "Apache-2.0",
60
- "sideEffects": false,
61
- "main": "./lib/index.cjs",
62
- "module": "./esm/index.mjs",
63
- "types": "./esm/index.d.mts",
64
- "exports": {
65
- ".": {
66
- "types": "./esm/index.d.mts",
67
- "import": "./esm/index.mjs",
68
- "default": "./lib/index.cjs"
69
- },
70
- "./lib/schema": {
71
- "types": "./esm/schema/index.d.mts",
72
- "import": "./esm/schema/index.mjs",
73
- "default": "./lib/schema/index.cjs"
74
- },
75
- "./lib/schema/*": {
76
- "types": "./esm/schema/*.d.mts",
77
- "import": "./esm/schema/*.mjs",
78
- "default": "./lib/schema/*.cjs"
79
- },
80
- "./lib/*.js": {
81
- "types": "./esm/*.d.mts",
82
- "import": "./esm/*.mjs",
83
- "default": "./lib/*.cjs"
84
- },
85
- "./lib/*": {
86
- "types": "./esm/*.d.mts",
87
- "import": "./esm/*.mjs",
88
- "default": "./lib/*.cjs"
89
- }
90
- },
91
- "files": ["lib", "esm"],
92
- "repository": {
93
- "type": "git",
94
- "url": "https://github.com/ArcBlock/blockchain/tree/master/did/did-connect"
95
- },
96
- "scripts": {
97
- "lint": "biome check",
98
- "lint:fix": "biome check --write",
99
- "docs": "bun run gen-dts && bun run gen-docs && bun run cleanup-docs && bun run format-docs",
100
- "cleanup-docs": "node ../../scripts/cleanup-docs.js docs/README.md $npm_package_name",
101
- "gen-docs": "jsdoc2md lib/**/*.js lib/**/**/*.js > docs/README.md",
102
- "gen-dts": "j2d lib/index.js",
103
- "format-docs": "remark . -o",
104
- "test": "bun test",
105
- "coverage": "npm run test -- --coverage",
106
- "build": "tsdown",
107
- "build:watch": "tsdown -w",
108
- "clean": "rm -rf lib esm"
109
- },
110
- "resolutions": { "tweetnacl": "1.0.3" },
111
- "gitHead": "87990c8b5e215107fc587c1ced0d6b3e2cd2483e"
112
- };
113
- }));
114
-
115
- //#endregion
116
- Object.defineProperty(exports, 'default', {
117
- enumerable: true,
118
- get: function () {
119
- return require_package();
120
- }
121
- });
package/lib/protocol.cjs DELETED
@@ -1,46 +0,0 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
- let _ocap_util = require("@ocap/util");
3
- let _arcblock_jwt = require("@arcblock/jwt");
4
- let _ocap_mcrypto_lib_crypter_aes = require("@ocap/mcrypto/lib/crypter/aes");
5
- _ocap_mcrypto_lib_crypter_aes = require_rolldown_runtime.__toESM(_ocap_mcrypto_lib_crypter_aes);
6
-
7
- //#region src/protocol.ts
8
- const VERSION = "1.0.0";
9
- const decrypt = (data, config = {}, dataKey = "userInfo") => {
10
- try {
11
- (0, _arcblock_jwt.decode)(data[dataKey]);
12
- return data;
13
- } catch {}
14
- if (config.sharedKey && data.version === VERSION) data[dataKey] = _ocap_mcrypto_lib_crypter_aes.default.decrypt((0, _ocap_util.fromBase58)(data[dataKey]), config.sharedKey, "buffer").toString("utf8");
15
- return data;
16
- };
17
- const encrypt = (data, config = {}, dataKey = "authInfo") => {
18
- const { clientVersion, sharedKey } = config || {};
19
- if (data.sensitive && sharedKey && clientVersion === VERSION) {
20
- data.version = VERSION;
21
- data[dataKey] = _ocap_mcrypto_lib_crypter_aes.default.encrypt(data[dataKey], sharedKey, "base58");
22
- }
23
- delete data.sensitive;
24
- return data;
25
- };
26
- const PROTECTED_KEYS = [
27
- "challenge",
28
- "nonce",
29
- "sharedKey",
30
- "encryptionKey"
31
- ];
32
- const SESSION_STATUS = {
33
- CREATED: "created",
34
- SUCCEED: "succeed",
35
- ERROR: "error",
36
- BUSY: "busy",
37
- SCANNED: "scanned",
38
- FORBIDDEN: "forbidden"
39
- };
40
-
41
- //#endregion
42
- exports.PROTECTED_KEYS = PROTECTED_KEYS;
43
- exports.SESSION_STATUS = SESSION_STATUS;
44
- exports.VERSION = VERSION;
45
- exports.decrypt = decrypt;
46
- exports.encrypt = encrypt;
@@ -1,15 +0,0 @@
1
- //#region src/protocol.d.ts
2
- declare const VERSION = "1.0.0";
3
- declare const decrypt: (data: any, config?: any, dataKey?: string) => any;
4
- declare const encrypt: (data: any, config?: any, dataKey?: string) => any;
5
- declare const PROTECTED_KEYS: string[];
6
- declare const SESSION_STATUS: {
7
- readonly CREATED: "created";
8
- readonly SUCCEED: "succeed";
9
- readonly ERROR: "error";
10
- readonly BUSY: "busy";
11
- readonly SCANNED: "scanned";
12
- readonly FORBIDDEN: "forbidden";
13
- };
14
- //#endregion
15
- export { PROTECTED_KEYS, SESSION_STATUS, VERSION, decrypt, encrypt };