@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,120 +0,0 @@
1
- import { ConnectRequest, ConnectResponse } from "../types.mjs";
2
- import BaseHandler from "./base.mjs";
3
- import "../index.mjs";
4
-
5
- //#region src/handlers/wallet.d.ts
6
-
7
- /**
8
- * Events that are emitted during an DID Connect process
9
- *
10
- * - scanned: when the qrcode is scanned by wallet
11
- * - succeed: when authentication complete
12
- * - error: when something goes wrong
13
- *
14
- * @class WalletHandlers
15
- * @extends {EventEmitter}
16
- */
17
- declare class WalletHandlers extends BaseHandler {
18
- options: {
19
- prefix: string;
20
- cleanupDelay: number;
21
- tokenKey: string;
22
- encKey: string;
23
- versionKey: string;
24
- };
25
- /**
26
- * Creates an instance of DID Auth Handlers.
27
- *
28
- * @class
29
- * @param {object} config
30
- * @param {object} config.tokenStorage - function to generate action token
31
- * @param {object} config.authenticator - Authenticator instance that can to jwt sign/verify
32
- * @param {function} [config.pathTransformer=null] - how should we update pathname
33
- * @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
34
- * @param {object} [config.options={}] - custom options to define all handlers attached
35
- * @param {string} [config.options.prefix='/api/did'] - url prefix for this group endpoints
36
- * @param {number} [config.options.cleanupDelay=60000] - how long to wait before cleanup finished session
37
- * @param {string} [config.options.tokenKey='_t_'] - query param key for `token`
38
- * @param {string} [config.options.encKey='_ek_'] - query param key for encryption key
39
- * @param {string} [config.options.versionKey='_v_'] - query param key for protocol `version`
40
- */
41
- constructor({
42
- pathTransformer,
43
- tokenStorage,
44
- authenticator,
45
- onConnect,
46
- options
47
- }: {
48
- pathTransformer?: (v: string) => string;
49
- tokenStorage: any;
50
- authenticator: any;
51
- onConnect?: (...args: any[]) => any;
52
- options?: Partial<{
53
- prefix: string;
54
- cleanupDelay: number;
55
- tokenKey: string;
56
- encKey: string;
57
- versionKey: string;
58
- }>;
59
- });
60
- /**
61
- * Attach routes and handlers for authenticator
62
- * Now express app have route handlers attached to the following url
63
- * - `GET /api/did/{action}/token` create new token
64
- * - `GET /api/did/{action}/status` check for token status
65
- * - `GET /api/did/{action}/timeout` expire a token
66
- * - `GET /api/did/{action}/auth` create auth response
67
- * - `POST /api/did/{action}/auth` process payment request
68
- *
69
- * @method
70
- * @param {object} config
71
- * @param {object} config.app - express instance to attach routes to
72
- * @param {object} [config.claims] - claims for this request
73
- * @param {string} config.action - action of this group of routes
74
- * @param {function} [config.onStart=noop] - callback when a new action start
75
- * @param {function} [config.onConnect=noop] - callback when a new action start
76
- * @param {function} config.onAuth - callback when user completed auth in DID Wallet, and data posted back
77
- * @param {function} [config.onDecline=noop] - callback when user has declined in wallet
78
- * @param {function} [config.onComplete=noop] - callback when the whole auth process is done, action token is removed
79
- * @param {function} [config.onExpire=noop] - callback when the action token expired
80
- * @param {function} [config.onError=console.error] - callback when there are some errors
81
- * @param {boolean|string|did} [config.authPrincipal=true] - whether should we do auth principal claim first
82
- * @param {boolean} [config.persistentDynamicClaims=false] - whether should we persist dynamic claims
83
- * @return void
84
- */
85
- attach({
86
- app,
87
- action,
88
- claims,
89
- onStart,
90
- onConnect,
91
- onAuth,
92
- onDecline,
93
- onComplete,
94
- onExpire,
95
- onError,
96
- authPrincipal,
97
- persistentDynamicClaims
98
- }: {
99
- app: any;
100
- action: string;
101
- claims?: any;
102
- onStart?: (...args: any[]) => any;
103
- onConnect?: (...args: any[]) => any;
104
- onAuth: (...args: any[]) => any;
105
- onDecline?: (...args: any[]) => any;
106
- onComplete?: (...args: any[]) => any;
107
- onExpire?: (...args: any[]) => any;
108
- onError?: (...args: any[]) => any;
109
- authPrincipal?: boolean | string | any;
110
- persistentDynamicClaims?: boolean;
111
- }): {
112
- generateSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
113
- expireSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
114
- checkSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
115
- onAuthRequest: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
116
- onAuthResponse: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
117
- };
118
- }
119
- //#endregion
120
- export { WalletHandlers as default };
@@ -1,139 +0,0 @@
1
- import { __require } from "../_virtual/rolldown_runtime.mjs";
2
- import { require_package } from "../did/did-connect/package.mjs";
3
- import { isHonoApp } from "../adapters/detect.mjs";
4
- import { attachExpress } from "../adapters/express.mjs";
5
- import { attachHono } from "../adapters/hono.mjs";
6
- import base_default from "./base.mjs";
7
- import createHandlers from "./util.mjs";
8
-
9
- //#region src/handlers/wallet.ts
10
- const debug = __require("debug")(`${require_package().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 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 } = createHandlers({
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 (isHonoApp(app)) return attachHono({
123
- app,
124
- prefix,
125
- action,
126
- handlers: handlerFns
127
- });
128
- return attachExpress({
129
- app,
130
- prefix,
131
- action,
132
- handlers: handlerFns
133
- });
134
- }
135
- };
136
- var wallet_default = WalletHandlers;
137
-
138
- //#endregion
139
- export { wallet_default as default };
package/esm/index.d.mts DELETED
@@ -1,8 +0,0 @@
1
- import { isExpressApp, isHonoApp } from "./adapters/detect.mjs";
2
- import { ConnectRequest, ConnectResponse, NextFunction } from "./types.mjs";
3
- import { attachExpress } from "./adapters/express.mjs";
4
- import { attachHono, createHonoRequest, createHonoResponse } from "./adapters/hono.mjs";
5
- import WalletAuthenticator from "./authenticator/wallet.mjs";
6
- import CloudflareKVStorage from "./storage/kv.mjs";
7
- import WalletHandlers from "./handlers/wallet.mjs";
8
- export { CloudflareKVStorage, type ConnectRequest, type ConnectResponse, type NextFunction, WalletAuthenticator, WalletHandlers, attachExpress, attachHono, createHonoRequest, createHonoResponse, isExpressApp, isHonoApp };
package/esm/index.mjs DELETED
@@ -1,8 +0,0 @@
1
- import wallet_default from "./authenticator/wallet.mjs";
2
- import { isExpressApp, isHonoApp } from "./adapters/detect.mjs";
3
- import { attachExpress } from "./adapters/express.mjs";
4
- import { attachHono, createHonoRequest, createHonoResponse } from "./adapters/hono.mjs";
5
- import wallet_default$1 from "./handlers/wallet.mjs";
6
- import kv_default from "./storage/kv.mjs";
7
-
8
- export { kv_default as CloudflareKVStorage, wallet_default as WalletAuthenticator, wallet_default$1 as WalletHandlers, attachExpress, attachHono, createHonoRequest, createHonoResponse, isExpressApp, isHonoApp };