@arcblock/did-connect-js 1.30.0 → 4.0.0-beta.10

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 (124) 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 +252 -0
  18. package/dist/authenticator/wallet.d.ts.map +1 -0
  19. package/dist/authenticator/wallet.js +590 -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 +805 -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 +11 -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 +11 -0
  42. package/dist/schema/claims.d.ts.map +1 -0
  43. package/dist/schema/claims.js +226 -0
  44. package/dist/schema/claims.js.map +1 -0
  45. package/dist/schema/index.d.ts +4 -0
  46. package/dist/schema/index.d.ts.map +1 -0
  47. package/dist/schema/index.js +89 -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/dist/utils/helpers.d.ts +19 -0
  58. package/dist/utils/helpers.d.ts.map +1 -0
  59. package/dist/utils/helpers.js +77 -0
  60. package/dist/utils/helpers.js.map +1 -0
  61. package/package.json +51 -107
  62. package/LICENSE +0 -13
  63. package/README.md +0 -210
  64. package/esm/_virtual/rolldown_runtime.mjs +0 -8
  65. package/esm/adapters/detect.d.mts +0 -11
  66. package/esm/adapters/detect.mjs +0 -16
  67. package/esm/adapters/express.d.mts +0 -48
  68. package/esm/adapters/express.mjs +0 -39
  69. package/esm/adapters/hono.d.mts +0 -57
  70. package/esm/adapters/hono.mjs +0 -164
  71. package/esm/authenticator/base.d.mts +0 -23
  72. package/esm/authenticator/base.mjs +0 -88
  73. package/esm/authenticator/wallet.d.mts +0 -270
  74. package/esm/authenticator/wallet.mjs +0 -556
  75. package/esm/did/did-connect/package.mjs +0 -118
  76. package/esm/handlers/base.d.mts +0 -32
  77. package/esm/handlers/base.mjs +0 -37
  78. package/esm/handlers/util.d.mts +0 -70
  79. package/esm/handlers/util.mjs +0 -739
  80. package/esm/handlers/wallet.d.mts +0 -120
  81. package/esm/handlers/wallet.mjs +0 -139
  82. package/esm/index.d.mts +0 -8
  83. package/esm/index.mjs +0 -8
  84. package/esm/node_modules/valibot/dist/index.mjs +0 -736
  85. package/esm/protocol.d.mts +0 -15
  86. package/esm/protocol.mjs +0 -40
  87. package/esm/schema/claims.d.mts +0 -16
  88. package/esm/schema/claims.mjs +0 -216
  89. package/esm/schema/index.d.mts +0 -29
  90. package/esm/schema/index.mjs +0 -75
  91. package/esm/storage/kv.d.mts +0 -33
  92. package/esm/storage/kv.mjs +0 -55
  93. package/esm/types.d.mts +0 -55
  94. package/esm/types.mjs +0 -1
  95. package/lib/_virtual/rolldown_runtime.cjs +0 -31
  96. package/lib/adapters/detect.cjs +0 -18
  97. package/lib/adapters/express.cjs +0 -41
  98. package/lib/adapters/express.d.cts +0 -48
  99. package/lib/adapters/hono.cjs +0 -167
  100. package/lib/adapters/hono.d.cts +0 -57
  101. package/lib/authenticator/base.cjs +0 -91
  102. package/lib/authenticator/base.d.cts +0 -23
  103. package/lib/authenticator/wallet.cjs +0 -565
  104. package/lib/authenticator/wallet.d.cts +0 -270
  105. package/lib/did/did-connect/package.cjs +0 -121
  106. package/lib/handlers/base.cjs +0 -40
  107. package/lib/handlers/base.d.cts +0 -32
  108. package/lib/handlers/util.cjs +0 -759
  109. package/lib/handlers/util.d.cts +0 -70
  110. package/lib/handlers/wallet.cjs +0 -139
  111. package/lib/handlers/wallet.d.cts +0 -119
  112. package/lib/index.cjs +0 -16
  113. package/lib/index.d.cts +0 -8
  114. package/lib/node_modules/valibot/dist/index.cjs +0 -756
  115. package/lib/protocol.cjs +0 -46
  116. package/lib/protocol.d.cts +0 -15
  117. package/lib/schema/claims.cjs +0 -218
  118. package/lib/schema/claims.d.cts +0 -16
  119. package/lib/schema/index.cjs +0 -79
  120. package/lib/schema/index.d.cts +0 -29
  121. package/lib/storage/kv.cjs +0 -57
  122. package/lib/storage/kv.d.cts +0 -33
  123. package/lib/types.cjs +0 -0
  124. 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('../did/did-connect/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 };