@arcblock/did-connect-js 1.29.22 → 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 -106
  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 -120
  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 -760
  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 -123
  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,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 "../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 };
package/esm/package.mjs DELETED
@@ -1,120 +0,0 @@
1
- import { __commonJSMin } from "./_virtual/rolldown_runtime.mjs";
2
-
3
- //#region package.json
4
- var require_package = /* @__PURE__ */ __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
- "semver": "^7.6.3",
34
- "tweetnacl-sealedbox-js": "^1.2.0"
35
- },
36
- "devDependencies": {
37
- "@arcblock/did-agent-storage-memory": "^1.8.0",
38
- "@arcblock/did-connect-storage-memory": "^1.8.0",
39
- "@ocap/e2e-test": "workspace:*",
40
- "@types/cors": "^2.8.17",
41
- "@types/debug": "^4.1.12",
42
- "@types/json-stable-stringify": "^1.0.36",
43
- "@types/lodash": "^4.17.13",
44
- "@types/node": "^22.7.5",
45
- "@types/semver": "^7.5.8",
46
- "axios": "^1.13.4",
47
- "remark-cli": "^10.0.1",
48
- "remark-preset-github": "^4.0.4",
49
- "hono": "^4.7.0",
50
- "tsdown": "^0.18.4",
51
- "tweetnacl": "^1.0.3"
52
- },
53
- "remarkConfig": { "plugins": ["preset-github", [{ "repository": "ArcBlock/blockchain" }]] },
54
- "homepage": "https://www.arcblock.io/docs/did-connect-sdk",
55
- "keywords": [
56
- "blockchain",
57
- "arcblock",
58
- "sdk",
59
- "nodejs"
60
- ],
61
- "license": "Apache-2.0",
62
- "sideEffects": false,
63
- "main": "./lib/index.cjs",
64
- "module": "./esm/index.mjs",
65
- "types": "./esm/index.d.mts",
66
- "exports": {
67
- ".": {
68
- "types": "./esm/index.d.mts",
69
- "import": "./esm/index.mjs",
70
- "default": "./lib/index.cjs"
71
- },
72
- "./lib/schema": {
73
- "types": "./esm/schema/index.d.mts",
74
- "import": "./esm/schema/index.mjs",
75
- "default": "./lib/schema/index.cjs"
76
- },
77
- "./lib/schema/*": {
78
- "types": "./esm/schema/*.d.mts",
79
- "import": "./esm/schema/*.mjs",
80
- "default": "./lib/schema/*.cjs"
81
- },
82
- "./lib/*.js": {
83
- "types": "./esm/*.d.mts",
84
- "import": "./esm/*.mjs",
85
- "default": "./lib/*.cjs"
86
- },
87
- "./lib/*": {
88
- "types": "./esm/*.d.mts",
89
- "import": "./esm/*.mjs",
90
- "default": "./lib/*.cjs"
91
- }
92
- },
93
- "files": ["lib", "esm"],
94
- "repository": {
95
- "type": "git",
96
- "url": "https://github.com/ArcBlock/blockchain/tree/master/did/did-connect"
97
- },
98
- "scripts": {
99
- "lint": "biome check",
100
- "lint:fix": "biome check --write",
101
- "docs": "bun run gen-dts && bun run gen-docs && bun run cleanup-docs && bun run format-docs",
102
- "cleanup-docs": "node ../../scripts/cleanup-docs.js docs/README.md $npm_package_name",
103
- "gen-docs": "jsdoc2md lib/**/*.js lib/**/**/*.js > docs/README.md",
104
- "gen-dts": "j2d lib/index.js",
105
- "format-docs": "remark . -o",
106
- "test": "bun test",
107
- "coverage": "npm run test -- --coverage",
108
- "build": "tsdown",
109
- "build:watch": "tsdown -w",
110
- "clean": "rm -rf lib esm"
111
- },
112
- "resolutions": { "tweetnacl": "1.0.3" },
113
- "gitHead": "87990c8b5e215107fc587c1ced0d6b3e2cd2483e"
114
- };
115
- }));
116
-
117
- //#endregion
118
- export default require_package();
119
-
120
- export { require_package };
@@ -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 };
package/esm/protocol.mjs DELETED
@@ -1,40 +0,0 @@
1
- import { fromBase58 } from "@ocap/util";
2
- import { decode } from "@arcblock/jwt";
3
- import AES from "@ocap/mcrypto/lib/crypter/aes";
4
-
5
- //#region src/protocol.ts
6
- const VERSION = "1.0.0";
7
- const decrypt = (data, config = {}, dataKey = "userInfo") => {
8
- try {
9
- decode(data[dataKey]);
10
- return data;
11
- } catch {}
12
- if (config.sharedKey && data.version === VERSION) data[dataKey] = AES.decrypt(fromBase58(data[dataKey]), config.sharedKey, "buffer").toString("utf8");
13
- return data;
14
- };
15
- const encrypt = (data, config = {}, dataKey = "authInfo") => {
16
- const { clientVersion, sharedKey } = config || {};
17
- if (data.sensitive && sharedKey && clientVersion === VERSION) {
18
- data.version = VERSION;
19
- data[dataKey] = AES.encrypt(data[dataKey], sharedKey, "base58");
20
- }
21
- delete data.sensitive;
22
- return data;
23
- };
24
- const PROTECTED_KEYS = [
25
- "challenge",
26
- "nonce",
27
- "sharedKey",
28
- "encryptionKey"
29
- ];
30
- const SESSION_STATUS = {
31
- CREATED: "created",
32
- SUCCEED: "succeed",
33
- ERROR: "error",
34
- BUSY: "busy",
35
- SCANNED: "scanned",
36
- FORBIDDEN: "forbidden"
37
- };
38
-
39
- //#endregion
40
- export { PROTECTED_KEYS, SESSION_STATUS, VERSION, decrypt, encrypt };
@@ -1,18 +0,0 @@
1
- import { ObjectSchema } from "joi";
2
-
3
- //#region src/schema/claims.d.ts
4
- interface ClaimsSchema {
5
- authPrincipal: ObjectSchema;
6
- profile: ObjectSchema;
7
- signature: ObjectSchema;
8
- prepareTx: ObjectSchema;
9
- agreement: ObjectSchema;
10
- verifiableCredential: ObjectSchema;
11
- asset: ObjectSchema;
12
- assetOrVC: ObjectSchema;
13
- keyPair: ObjectSchema;
14
- encryptionKey: ObjectSchema;
15
- }
16
- declare const _default: (chainInfo: ObjectSchema) => ClaimsSchema;
17
- //#endregion
18
- export { ClaimsSchema, _default as default };
@@ -1,154 +0,0 @@
1
- import { Joi } from "@arcblock/validator";
2
- import { types } from "@ocap/mcrypto";
3
-
4
- //#region src/schema/claims.ts
5
- const trustedIssuerSchema = Joi.alternatives().try(Joi.object({
6
- did: Joi.DID().required(),
7
- endpoint: Joi.string().uri({ scheme: ["http", "https"] }).required()
8
- }), Joi.DID().required());
9
- const optionalUrlSchema = Joi.string().uri({
10
- scheme: ["http", "https"],
11
- allowRelative: true
12
- }).optional().default("").allow("");
13
- const requirementSchema = Joi.object({
14
- tokens: Joi.array().items(Joi.object({
15
- address: Joi.DID().required(),
16
- value: Joi.BN().positive().required()
17
- })).required(),
18
- assets: Joi.object({
19
- address: Joi.array().items(Joi.DID()).optional(),
20
- parent: Joi.array().items(Joi.DID()).optional(),
21
- issuer: Joi.array().items(Joi.DID()).optional(),
22
- amount: Joi.number().positive().min(1)
23
- }).optional()
24
- });
25
- const targetTypeSchema = Joi.object({
26
- key: Joi.string().valid(...Object.keys(types.KeyType).map((x) => x.toLowerCase())).default("ed25519"),
27
- hash: Joi.string().valid(...Object.keys(types.HashType).map((x) => x.toLowerCase())).default("sha3"),
28
- role: Joi.string().valid(...Object.keys(types.RoleType).map((x) => x.toLowerCase().split("_").pop())).default("account"),
29
- encoding: Joi.string().valid(...Object.keys(types.EncodingType).map((x) => x.toLowerCase())).default("base58")
30
- }).optional();
31
- var claims_default = (chainInfo) => {
32
- const options = {
33
- stripUnknown: true,
34
- noDefaults: false
35
- };
36
- const createStandardFields = (type, description) => ({
37
- type: Joi.string().valid(type).default(type),
38
- description: Joi.string().min(1).default(description),
39
- chainInfo,
40
- mfaCode: Joi.array().items(Joi.number().min(10).max(99).optional()).default([]),
41
- meta: Joi.any().optional().default({})
42
- });
43
- const authPrincipal = Joi.object({
44
- ...createStandardFields("authPrincipal", "Please continue with your account"),
45
- target: Joi.DID().optional().allow("").default(""),
46
- supervised: Joi.boolean().default(false),
47
- targetType: targetTypeSchema
48
- }).options(options);
49
- const keyPair = Joi.object({
50
- ...createStandardFields("keyPair", "Please create account to continue."),
51
- moniker: Joi.string().regex(/^[a-zA-Z0-9][-a-zA-Z0-9_]{2,128}$/).required(),
52
- declare: Joi.boolean().optional().default(true),
53
- migrateFrom: Joi.DID().optional().allow("").default(""),
54
- targetType: targetTypeSchema
55
- }).options(options);
56
- const encryptionKey = Joi.object({
57
- ...createStandardFields("encryptionKey", "Please provide encryptionKey to continue."),
58
- salt: Joi.string().required(),
59
- delegation: Joi.string().optional().allow("").default("")
60
- }).options(options);
61
- return {
62
- authPrincipal,
63
- profile: Joi.object({
64
- ...createStandardFields("profile", "Please provide your profile to continue."),
65
- items: Joi.array().items(Joi.string().valid("did", "fullName", "email", "phone", "signature", "avatar", "birthday", "url")).min(1).default(["fullName"])
66
- }).rename("fields", "items", {
67
- ignoreUndefined: true,
68
- override: true
69
- }).options(options),
70
- signature: Joi.object({
71
- ...createStandardFields("signature", "Sign this transaction or message to continue."),
72
- typeUrl: Joi.string().valid("fg:x:delegation", "fg:t:transaction", "mime:text/plain", "mime:text/html", "eth:transaction", "eth:standard-data", "eth:personal-data", "eth:typed-data", "eth:legacy-data").required(),
73
- display: Joi.string().allow("").default(""),
74
- method: Joi.string().allow("none", ...Object.keys(types.HashType).map((x) => x.toLowerCase())).optional().default("sha3"),
75
- digest: Joi.string().allow("").default(""),
76
- origin: Joi.string().allow("").default(""),
77
- nonce: Joi.string().allow("").default(""),
78
- requirement: requirementSchema.optional()
79
- }).options(options),
80
- prepareTx: Joi.object({
81
- ...createStandardFields("prepareTx", "Prepare and sign this transaction to continue."),
82
- display: Joi.string().allow("").default(""),
83
- partialTx: Joi.string().required(),
84
- nonce: Joi.string().allow("").default(""),
85
- requirement: requirementSchema.required()
86
- }).options(options),
87
- agreement: Joi.object({
88
- ...createStandardFields("agreement", "Confirm your agreement to continue."),
89
- uri: Joi.string().uri({ scheme: ["http", "https"] }).required().allow(""),
90
- method: Joi.string().allow(...Object.keys(types.HashType).map((x) => x.toLowerCase())).optional().default("sha2"),
91
- digest: Joi.string().required()
92
- }).options(options),
93
- verifiableCredential: Joi.object({
94
- ...createStandardFields("verifiableCredential", "Please present a verifiable credential to continue."),
95
- optional: Joi.boolean().default(false),
96
- claimUrl: optionalUrlSchema,
97
- acquireUrl: optionalUrlSchema,
98
- item: Joi.array().items(Joi.string().min(1).required()).min(1).optional(),
99
- target: Joi.DID().optional(),
100
- trustedIssuers: Joi.array().items(trustedIssuerSchema).min(1).optional(),
101
- tag: Joi.string().min(1).allow("").default(""),
102
- ownerDid: Joi.array().items(Joi.DID()).optional().default([]),
103
- filters: Joi.array().items(Joi.object({
104
- type: Joi.array().items(Joi.string().min(1).required()).min(1).optional(),
105
- target: Joi.DID().optional(),
106
- trustedIssuers: Joi.array().items(trustedIssuerSchema).min(1).optional(),
107
- tag: Joi.string().min(1).allow("").default(""),
108
- ownerDid: Joi.array().items(Joi.DID()).optional().default([]),
109
- claimUrl: optionalUrlSchema,
110
- acquireUrl: optionalUrlSchema
111
- })).optional()
112
- }).options(options),
113
- asset: Joi.object({
114
- ...createStandardFields("asset", "Please present an on chain asset to continue."),
115
- optional: Joi.boolean().default(false),
116
- address: Joi.DID().optional(),
117
- trustedIssuers: Joi.array().items(trustedIssuerSchema).min(1).optional(),
118
- trustedParents: Joi.array().items(Joi.DID().required()).min(1).optional(),
119
- tag: Joi.string().min(1).allow("").default(""),
120
- ownerDid: Joi.array().items(Joi.DID()).optional().default([]),
121
- consumed: Joi.boolean().optional(),
122
- acquireUrl: optionalUrlSchema,
123
- filters: Joi.array().items(Joi.object({
124
- address: Joi.DID().optional(),
125
- trustedIssuers: Joi.array().items(trustedIssuerSchema).min(1).optional(),
126
- trustedParents: Joi.array().items(Joi.DID().required()).min(1).optional(),
127
- tag: Joi.string().min(1).allow("").default(""),
128
- ownerDid: Joi.array().items(Joi.DID()).optional().default([]),
129
- consumed: Joi.boolean().optional(),
130
- acquireUrl: optionalUrlSchema
131
- })).optional()
132
- }).options(options),
133
- assetOrVC: Joi.object({
134
- ...createStandardFields("assetOrVC", "Please present NFT to continue."),
135
- filters: Joi.array().items(Joi.object({
136
- type: Joi.array().items(Joi.string().min(1).required()).min(1).optional(),
137
- address: Joi.DID().optional(),
138
- trustedIssuers: Joi.array().items(trustedIssuerSchema).min(1).optional(),
139
- trustedParents: Joi.array().items(Joi.DID().required()).min(1).optional(),
140
- tag: Joi.string().min(1).allow("").default(""),
141
- ownerDid: Joi.array().items(Joi.DID()).optional().default([]),
142
- consumed: Joi.boolean().optional(),
143
- claimUrl: optionalUrlSchema,
144
- acquireUrl: optionalUrlSchema
145
- })).required().min(1),
146
- optional: Joi.boolean().default(false)
147
- }).options(options),
148
- keyPair,
149
- encryptionKey
150
- };
151
- };
152
-
153
- //#endregion
154
- export { claims_default as default };
@@ -1,9 +0,0 @@
1
- import { ClaimsSchema } from "./claims.mjs";
2
- import * as joi0 from "joi";
3
-
4
- //#region src/schema/index.d.ts
5
- declare const chainInfo: joi0.ObjectSchema<any>;
6
- declare const appInfo: joi0.ObjectSchema<any>;
7
- declare const claims: ClaimsSchema;
8
- //#endregion
9
- export { appInfo, chainInfo, claims };