@owlmeans/client-auth 0.1.0

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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +526 -0
  3. package/build/.gitkeep +0 -0
  4. package/build/components/dispatcher/component.d.ts +3 -0
  5. package/build/components/dispatcher/component.d.ts.map +1 -0
  6. package/build/components/dispatcher/component.js +70 -0
  7. package/build/components/dispatcher/component.js.map +1 -0
  8. package/build/components/dispatcher/index.d.ts +3 -0
  9. package/build/components/dispatcher/index.d.ts.map +1 -0
  10. package/build/components/dispatcher/index.js +3 -0
  11. package/build/components/dispatcher/index.js.map +1 -0
  12. package/build/components/dispatcher/types.d.ts +21 -0
  13. package/build/components/dispatcher/types.d.ts.map +1 -0
  14. package/build/components/dispatcher/types.js +2 -0
  15. package/build/components/dispatcher/types.js.map +1 -0
  16. package/build/components/index.d.ts +2 -0
  17. package/build/components/index.d.ts.map +1 -0
  18. package/build/components/index.js +2 -0
  19. package/build/components/index.js.map +1 -0
  20. package/build/consts.d.ts +4 -0
  21. package/build/consts.d.ts.map +1 -0
  22. package/build/consts.js +4 -0
  23. package/build/consts.js.map +1 -0
  24. package/build/helper.d.ts +4 -0
  25. package/build/helper.d.ts.map +1 -0
  26. package/build/helper.js +28 -0
  27. package/build/helper.js.map +1 -0
  28. package/build/index.d.ts +7 -0
  29. package/build/index.d.ts.map +1 -0
  30. package/build/index.js +6 -0
  31. package/build/index.js.map +1 -0
  32. package/build/manager/components/authentication/component.d.ts +3 -0
  33. package/build/manager/components/authentication/component.d.ts.map +1 -0
  34. package/build/manager/components/authentication/component.js +28 -0
  35. package/build/manager/components/authentication/component.js.map +1 -0
  36. package/build/manager/components/authentication/consts.d.ts +2 -0
  37. package/build/manager/components/authentication/consts.d.ts.map +1 -0
  38. package/build/manager/components/authentication/consts.js +2 -0
  39. package/build/manager/components/authentication/consts.js.map +1 -0
  40. package/build/manager/components/authentication/control.d.ts +6 -0
  41. package/build/manager/components/authentication/control.d.ts.map +1 -0
  42. package/build/manager/components/authentication/control.js +146 -0
  43. package/build/manager/components/authentication/control.js.map +1 -0
  44. package/build/manager/components/authentication/index.d.ts +4 -0
  45. package/build/manager/components/authentication/index.d.ts.map +1 -0
  46. package/build/manager/components/authentication/index.js +4 -0
  47. package/build/manager/components/authentication/index.js.map +1 -0
  48. package/build/manager/components/authentication/types.d.ts +57 -0
  49. package/build/manager/components/authentication/types.d.ts.map +1 -0
  50. package/build/manager/components/authentication/types.js +2 -0
  51. package/build/manager/components/authentication/types.js.map +1 -0
  52. package/build/manager/components/index.d.ts +4 -0
  53. package/build/manager/components/index.d.ts.map +1 -0
  54. package/build/manager/components/index.js +3 -0
  55. package/build/manager/components/index.js.map +1 -0
  56. package/build/manager/components/tunnel-consumer.d.ts +4 -0
  57. package/build/manager/components/tunnel-consumer.d.ts.map +1 -0
  58. package/build/manager/components/tunnel-consumer.js +11 -0
  59. package/build/manager/components/tunnel-consumer.js.map +1 -0
  60. package/build/manager/components/types.d.ts +10 -0
  61. package/build/manager/components/types.d.ts.map +1 -0
  62. package/build/manager/components/types.js +2 -0
  63. package/build/manager/components/types.js.map +1 -0
  64. package/build/manager/errors.d.ts +6 -0
  65. package/build/manager/errors.d.ts.map +1 -0
  66. package/build/manager/errors.js +11 -0
  67. package/build/manager/errors.js.map +1 -0
  68. package/build/manager/index.d.ts +4 -0
  69. package/build/manager/index.d.ts.map +1 -0
  70. package/build/manager/index.js +4 -0
  71. package/build/manager/index.js.map +1 -0
  72. package/build/manager/modules.d.ts +2 -0
  73. package/build/manager/modules.d.ts.map +1 -0
  74. package/build/manager/modules.js +16 -0
  75. package/build/manager/modules.js.map +1 -0
  76. package/build/manager/plugins/basic-ed25519.d.ts +3 -0
  77. package/build/manager/plugins/basic-ed25519.d.ts.map +1 -0
  78. package/build/manager/plugins/basic-ed25519.js +33 -0
  79. package/build/manager/plugins/basic-ed25519.js.map +1 -0
  80. package/build/manager/plugins/exports.d.ts +6 -0
  81. package/build/manager/plugins/exports.d.ts.map +1 -0
  82. package/build/manager/plugins/exports.js +5 -0
  83. package/build/manager/plugins/exports.js.map +1 -0
  84. package/build/manager/plugins/index.d.ts +6 -0
  85. package/build/manager/plugins/index.d.ts.map +1 -0
  86. package/build/manager/plugins/index.js +9 -0
  87. package/build/manager/plugins/index.js.map +1 -0
  88. package/build/manager/plugins/re-captcha.d.ts +3 -0
  89. package/build/manager/plugins/re-captcha.d.ts.map +1 -0
  90. package/build/manager/plugins/re-captcha.js +26 -0
  91. package/build/manager/plugins/re-captcha.js.map +1 -0
  92. package/build/manager/plugins/tunnel/consts.d.ts +4 -0
  93. package/build/manager/plugins/tunnel/consts.d.ts.map +1 -0
  94. package/build/manager/plugins/tunnel/consts.js +9 -0
  95. package/build/manager/plugins/tunnel/consts.js.map +1 -0
  96. package/build/manager/plugins/tunnel/index.d.ts +4 -0
  97. package/build/manager/plugins/tunnel/index.d.ts.map +1 -0
  98. package/build/manager/plugins/tunnel/index.js +3 -0
  99. package/build/manager/plugins/tunnel/index.js.map +1 -0
  100. package/build/manager/plugins/tunnel/types.d.ts +13 -0
  101. package/build/manager/plugins/tunnel/types.d.ts.map +1 -0
  102. package/build/manager/plugins/tunnel/types.js +2 -0
  103. package/build/manager/plugins/tunnel/types.js.map +1 -0
  104. package/build/manager/plugins/tunnel/wallet.d.ts +4 -0
  105. package/build/manager/plugins/tunnel/wallet.d.ts.map +1 -0
  106. package/build/manager/plugins/tunnel/wallet.js +32 -0
  107. package/build/manager/plugins/tunnel/wallet.js.map +1 -0
  108. package/build/manager/plugins/tunnel-consumer.d.ts +3 -0
  109. package/build/manager/plugins/tunnel-consumer.d.ts.map +1 -0
  110. package/build/manager/plugins/tunnel-consumer.js +81 -0
  111. package/build/manager/plugins/tunnel-consumer.js.map +1 -0
  112. package/build/manager/plugins/types.d.ts +11 -0
  113. package/build/manager/plugins/types.d.ts.map +1 -0
  114. package/build/manager/plugins/types.js +2 -0
  115. package/build/manager/plugins/types.js.map +1 -0
  116. package/build/modules.d.ts +4 -0
  117. package/build/modules.d.ts.map +1 -0
  118. package/build/modules.js +9 -0
  119. package/build/modules.js.map +1 -0
  120. package/build/service.d.ts +6 -0
  121. package/build/service.d.ts.map +1 -0
  122. package/build/service.js +71 -0
  123. package/build/service.js.map +1 -0
  124. package/build/types.d.ts +13 -0
  125. package/build/types.d.ts.map +1 -0
  126. package/build/types.js +2 -0
  127. package/build/types.js.map +1 -0
  128. package/package.json +79 -0
  129. package/src/components/dispatcher/component.tsx +84 -0
  130. package/src/components/dispatcher/index.ts +3 -0
  131. package/src/components/dispatcher/types.ts +24 -0
  132. package/src/components/index.ts +2 -0
  133. package/src/consts.ts +6 -0
  134. package/src/helper.ts +39 -0
  135. package/src/index.ts +7 -0
  136. package/src/manager/README.md +463 -0
  137. package/src/manager/components/authentication/component.tsx +34 -0
  138. package/src/manager/components/authentication/consts.ts +2 -0
  139. package/src/manager/components/authentication/control.ts +193 -0
  140. package/src/manager/components/authentication/index.ts +4 -0
  141. package/src/manager/components/authentication/types.ts +74 -0
  142. package/src/manager/components/index.ts +4 -0
  143. package/src/manager/components/tunnel-consumer.tsx +15 -0
  144. package/src/manager/components/types.ts +11 -0
  145. package/src/manager/errors.ts +14 -0
  146. package/src/manager/index.ts +4 -0
  147. package/src/manager/modules.ts +18 -0
  148. package/src/manager/plugins/basic-ed25519.tsx +42 -0
  149. package/src/manager/plugins/exports.ts +5 -0
  150. package/src/manager/plugins/index.ts +13 -0
  151. package/src/manager/plugins/re-captcha.tsx +31 -0
  152. package/src/manager/plugins/tunnel/consts.ts +12 -0
  153. package/src/manager/plugins/tunnel/index.ts +5 -0
  154. package/src/manager/plugins/tunnel/types.ts +15 -0
  155. package/src/manager/plugins/tunnel/wallet.ts +43 -0
  156. package/src/manager/plugins/tunnel-consumer.tsx +100 -0
  157. package/src/manager/plugins/types.ts +14 -0
  158. package/src/modules.ts +13 -0
  159. package/src/service.ts +106 -0
  160. package/src/types.ts +15 -0
  161. package/tsconfig.json +15 -0
  162. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AuthenticationStage, AuthenticationType } from '@owlmeans/auth';
3
+ import { useEffect } from 'react';
4
+ import { makeKeyPairModel } from '@owlmeans/basic-keys';
5
+ import { AuthenCredError } from '../errors.js';
6
+ export const ed25519BasicUIPlugin = {
7
+ type: AuthenticationType.BasicEd25519,
8
+ Implementation: Renderer => ({ type, stage, control, params }) => {
9
+ type = type ?? AuthenticationType.BasicEd25519;
10
+ Renderer = Renderer ?? ed25519BasicUIPlugin.Renderer;
11
+ // BasicEd25519 authentication request allowance unconditionally
12
+ // (no input or additional challenges required)
13
+ useEffect(() => {
14
+ if (control.stage === AuthenticationStage.Init) {
15
+ void control.requestAllowence();
16
+ }
17
+ }, [type]);
18
+ if (Renderer == null) {
19
+ throw new SyntaxError('Renderer is not defined for BasicEd25519 plugin');
20
+ }
21
+ return _jsx(Renderer, { type: type, stage: stage, control: control, params: params });
22
+ },
23
+ authenticate: async (credentials) => {
24
+ const key = makeKeyPairModel(credentials.credential);
25
+ if (credentials.userId !== key.exportAddress()) {
26
+ throw new AuthenCredError('credentials-missmatch');
27
+ }
28
+ credentials.credential = await key.sign(credentials.challenge);
29
+ // We don't use it - just type compatibility
30
+ return { token: '' };
31
+ }
32
+ };
33
+ //# sourceMappingURL=basic-ed25519.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic-ed25519.js","sourceRoot":"","sources":["../../../src/manager/plugins/basic-ed25519.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,MAAM,CA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@@
1
+ export type * from './types.js';
2
+ export * from './tunnel/index.js';
3
+ export * from './basic-ed25519.js';
4
+ export * from './re-captcha.js';
5
+ export * from './tunnel-consumer.js';
6
+ //# sourceMappingURL=exports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../../src/manager/plugins/exports.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1,5 @@
1
+ export * from './tunnel/index.js';
2
+ export * from './basic-ed25519.js';
3
+ export * from './re-captcha.js';
4
+ export * from './tunnel-consumer.js';
5
+ //# sourceMappingURL=exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.js","sourceRoot":"","sources":["../../../src/manager/plugins/exports.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { ClientAuthType } from '../components/index.js';
2
+ import { AuthenticationPlugin } from './types.js';
3
+ export declare const plugins: {
4
+ [type: ClientAuthType]: AuthenticationPlugin;
5
+ };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/manager/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAI5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAIjD,eAAO,MAAM,OAAO,EAAE;IAAE,CAAC,IAAI,EAAE,cAAc,GAAG,oBAAoB,CAAA;CAAO,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { AuthenticationType } from '@owlmeans/auth';
2
+ import { ed25519BasicUIPlugin } from './basic-ed25519.js';
3
+ import { reCaptchaPlugin } from './re-captcha.js';
4
+ import { tunnelConsumerUIPlugin } from './tunnel-consumer.js';
5
+ export const plugins = {};
6
+ plugins[AuthenticationType.BasicEd25519] = ed25519BasicUIPlugin;
7
+ plugins[AuthenticationType.ReCaptcha] = reCaptchaPlugin;
8
+ plugins[AuthenticationType.WalletConsumer] = tunnelConsumerUIPlugin;
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/manager/plugins/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,MAAM,CAAC,MAAM,OAAO,GAAqD,EAAE,CAAA;AAE3E,OAAO,CAAC,kBAAkB,CAAC,YAAY,CAAC,GAAG,oBAAoB,CAAA;AAC/D,OAAO,CAAC,kBAAkB,CAAC,SAAS,CAAC,GAAG,eAAe,CAAA;AACvD,OAAO,CAAC,kBAAkB,CAAC,cAAc,CAAC,GAAG,sBAAsB,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { AuthenticationPlugin } from './types.js';
2
+ export declare const reCaptchaPlugin: AuthenticationPlugin;
3
+ //# sourceMappingURL=re-captcha.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"re-captcha.d.ts","sourceRoot":"","sources":["../../../src/manager/plugins/re-captcha.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAGtD,eAAO,MAAM,eAAe,EAAE,oBA0B7B,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AuthenticationStage, AuthenticationType } from '@owlmeans/auth';
3
+ import { useEffect } from 'react';
4
+ export const reCaptchaPlugin = {
5
+ type: AuthenticationType.ReCaptcha,
6
+ Implementation: Renderer => ({ type, stage, control, params }) => {
7
+ Renderer = Renderer ?? reCaptchaPlugin.Renderer;
8
+ // ReCaptcha authentication requests allowance unconditionally
9
+ // (no input or additional challenges required)
10
+ useEffect(() => {
11
+ if (control.stage === AuthenticationStage.Init) {
12
+ void control.requestAllowence({ type, source: control.source });
13
+ }
14
+ }, [type]);
15
+ if (Renderer == null) {
16
+ throw new SyntaxError('Renderer is not defined for ReCaptcha plugin');
17
+ }
18
+ return _jsx(Renderer, { type: type, stage: stage, control: control, params: params });
19
+ },
20
+ /**
21
+ * Actually we don't need to do anything here cause ReCaptcha server
22
+ * did it for us.
23
+ */
24
+ authenticate: async () => ({ token: '' })
25
+ };
26
+ //# sourceMappingURL=re-captcha.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"re-captcha.js","sourceRoot":"","sources":["../../../src/manager/plugins/re-captcha.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjC,MAAM,CAAC,MAAM,eAAe,GAAyB;IACnD,IAAI,EAAE,kBAAkB,CAAC,SAAS;IAElC,cAAc,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;QAC/D,QAAQ,GAAG,QAAQ,IAAI,eAAe,CAAC,QAAQ,CAAA;QAE/C,+DAA+D;QAC/D,+CAA+C;QAC/C,SAAS,CAAC,GAAG,EAAE;YACb,IAAI,OAAO,CAAC,KAAK,KAAK,mBAAmB,CAAC,IAAI,EAAE,CAAC;gBAC/C,KAAK,OAAO,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;YACjE,CAAC;QACH,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;QAEV,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,WAAW,CAAC,8CAA8C,CAAC,CAAA;QACvE,CAAC;QAED,OAAO,KAAC,QAAQ,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAI,CAAA;IACjF,CAAC;IAED;;;OAGG;IACH,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;CAC1C,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { JSONSchemaType } from 'ajv';
2
+ import type { PinForm } from './types.js';
3
+ export declare const PinSchema: JSONSchemaType<PinForm>;
4
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../../src/manager/plugins/tunnel/consts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,eAAO,MAAM,SAAS,EAAE,cAAc,CAAC,OAAO,CAO7C,CAAA"}
@@ -0,0 +1,9 @@
1
+ export const PinSchema = {
2
+ type: 'object',
3
+ properties: {
4
+ pin: { type: 'string', minLength: 2, maxLength: 12 }
5
+ },
6
+ required: ['pin'],
7
+ additionalProperties: false,
8
+ };
9
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../../../../src/manager/plugins/tunnel/consts.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,SAAS,GAA4B;IAChD,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;KACrD;IACD,QAAQ,EAAE,CAAC,KAAK,CAAC;IACjB,oBAAoB,EAAE,KAAK;CAC5B,CAAA"}
@@ -0,0 +1,4 @@
1
+ export type * from './types.js';
2
+ export * from './consts.js';
3
+ export * from './wallet.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/manager/plugins/tunnel/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './consts.js';
2
+ export * from './wallet.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/manager/plugins/tunnel/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,13 @@
1
+ import type { AuthenticationRendererProps } from '../../components/authentication/types.js';
2
+ import type { FC } from 'react';
3
+ import type { Connection } from '@owlmeans/socket';
4
+ export interface TunnelAuthenticationRenderer extends FC<TunnelAuthenticationRendererProps> {
5
+ }
6
+ export interface TunnelAuthenticationRendererProps extends AuthenticationRendererProps {
7
+ conn: Connection | null;
8
+ submit: (data: PinForm) => Promise<void>;
9
+ }
10
+ export interface PinForm {
11
+ pin: string;
12
+ }
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/manager/plugins/tunnel/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAA;AAC3F,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,MAAM,WAAW,4BAA6B,SAAQ,EAAE,CAAC,iCAAiC,CAAC;CAC1F;AAED,MAAM,WAAW,iCAAkC,SAAQ,2BAA2B;IACpF,IAAI,EAAE,UAAU,GAAG,IAAI,CAAA;IACvB,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACzC;AAED,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAA;CACZ"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/manager/plugins/tunnel/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { WalletFacade } from '@owlmeans/did';
2
+ import type { Connection } from '@owlmeans/socket';
3
+ export declare const createWalletFacade: (conn: Connection) => WalletFacade;
4
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../../src/manager/plugins/tunnel/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAGlD,eAAO,MAAM,kBAAkB,SAAU,UAAU,KAAG,YAsCrD,CAAA"}
@@ -0,0 +1,32 @@
1
+ import { base64, base64urlnopad } from '@scure/base';
2
+ export const createWalletFacade = (conn) => {
3
+ const facade = {
4
+ sign: async (entityId, payload, opts) => {
5
+ const result = await conn.call('sign', entityId, base64.encode(payload), opts);
6
+ return base64urlnopad.decode(result);
7
+ },
8
+ createKey: async (entityId, opts) => {
9
+ return await conn.call('createKey', entityId, opts);
10
+ },
11
+ getEntityKey: async (entityId, opts) => {
12
+ return await conn.call('getEntityKey', entityId, opts);
13
+ },
14
+ getMasterDid: async (opts) => {
15
+ return await conn.call('getMasterDid', opts);
16
+ },
17
+ selectKey: async (opts) => {
18
+ return await conn.call('selectKey', opts);
19
+ },
20
+ getPublicDetails: async (did, opts) => {
21
+ return await conn.call('getPublicDetails', did, opts);
22
+ },
23
+ requestPermissions: async (methods, opts) => {
24
+ return await conn.call('requestPermissions', methods, opts);
25
+ },
26
+ close: async () => {
27
+ await conn.close();
28
+ }
29
+ };
30
+ return facade;
31
+ };
32
+ //# sourceMappingURL=wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../../src/manager/plugins/tunnel/wallet.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAgB,EAAgB,EAAE;IACnE,MAAM,MAAM,GAAiB;QAC3B,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;YACtC,MAAM,MAAM,GAAW,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAA;YAEtF,OAAO,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACtC,CAAC;QAED,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;YAClC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;QACrD,CAAC;QAED,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;YACrC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;QACxD,CAAC;QAED,YAAY,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;YACzB,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;QAC9C,CAAC;QAED,SAAS,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;YACtB,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;QAC3C,CAAC;QAED,gBAAgB,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACpC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;QACvD,CAAC;QAED,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;YAC1C,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;QAC7D,CAAC;QAED,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;QACpB,CAAC;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { AuthenticationPlugin } from './types.js';
2
+ export declare const tunnelConsumerUIPlugin: AuthenticationPlugin;
3
+ //# sourceMappingURL=tunnel-consumer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tunnel-consumer.d.ts","sourceRoot":"","sources":["../../../src/manager/plugins/tunnel-consumer.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAStD,eAAO,MAAM,sBAAsB,EAAE,oBA8DpC,CAAA"}
@@ -0,0 +1,81 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useWs } from '@owlmeans/client-socket';
3
+ import { AUTH_SCOPE, AUTHEN_RELY, AuthenticationStage, AuthenticationType, AuthRole } from '@owlmeans/auth';
4
+ import { useCallback, useEffect } from 'react';
5
+ import { isEventMessage, SocketTimeout } from '@owlmeans/socket';
6
+ import { RELY_ACTION_TIMEOUT, RELY_PIN_PERFIX } from '@owlmeans/auth-common';
7
+ import { createWalletFacade } from './tunnel/wallet.js';
8
+ export const tunnelConsumerUIPlugin = {
9
+ type: AuthenticationType.WalletConsumer,
10
+ Implementation: renderer => ({ type, stage, control, params }) => {
11
+ type = type ?? AuthenticationType.WalletConsumer;
12
+ const Renderer = renderer
13
+ ?? tunnelConsumerUIPlugin.Renderer;
14
+ const connection = useWs(AUTHEN_RELY);
15
+ if (Renderer == null) {
16
+ throw new SyntaxError('Renderer is not defined for WalletConsumer plugin');
17
+ }
18
+ useEffect(() => {
19
+ if (connection != null) {
20
+ control.updateStage(AuthenticationStage.Allowence);
21
+ connection.auth(AuthenticationStage.Init, { type: AuthenticationType.RelyHandshake }).then(async (allowance) => {
22
+ control.allowance = allowance;
23
+ control.updateStage(AuthenticationStage.Authenticate);
24
+ connection.defaultCallTimeout = RELY_ACTION_TIMEOUT * 1000;
25
+ });
26
+ connection.authenticate = async (stage, payload) => {
27
+ if (stage === AuthenticationStage.Authenticated) {
28
+ try {
29
+ if (control.callback == null) {
30
+ throw new SyntaxError('Tunnel consumer requires a callback to provide connection object');
31
+ }
32
+ await control.callback(payload, createWalletFacade(connection));
33
+ control.updateStage(AuthenticationStage.Authentication);
34
+ }
35
+ catch (e) {
36
+ await connection.close();
37
+ await control.setError(e);
38
+ }
39
+ }
40
+ return [null, null];
41
+ };
42
+ return connection.listen(async (message) => {
43
+ if (isEventMessage(message) && message.event === 'close') {
44
+ await control.setError(new SocketTimeout('rely'));
45
+ }
46
+ });
47
+ }
48
+ }, [connection]);
49
+ const submit = useCallback(connection != null ? makeSubmit(connection, control) : async () => void 0, [connection != null]);
50
+ return _jsx(Renderer, { type: type, stage: stage, control: control, conn: connection, params: params, submit: submit });
51
+ },
52
+ authenticate: async (_credentials) => {
53
+ // We don't use it - just type compatibility
54
+ return { token: '' };
55
+ }
56
+ };
57
+ const makeSubmit = (conn, control) => async (data) => {
58
+ await control.updateStage(AuthenticationStage.Authentication);
59
+ try {
60
+ const auth = await conn.auth(AuthenticationStage.Authenticate, {
61
+ challenge: control.allowance?.challenge ?? '',
62
+ credential: RELY_PIN_PERFIX + data.pin,
63
+ type: control.type,
64
+ role: AuthRole.Guest,
65
+ userId: '',
66
+ scopes: [AUTH_SCOPE]
67
+ });
68
+ if (conn.stage === AuthenticationStage.Authenticated) {
69
+ if (control.callback == null) {
70
+ throw new SyntaxError('Tunnel consumer requires a callback to provide connection object');
71
+ }
72
+ await control.callback(auth, createWalletFacade(conn));
73
+ }
74
+ // (auth)
75
+ }
76
+ catch (e) {
77
+ await conn.close();
78
+ await control.setError(e);
79
+ }
80
+ };
81
+ //# sourceMappingURL=tunnel-consumer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tunnel-consumer.js","sourceRoot":"","sources":["../../../src/manager/plugins/tunnel-consumer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAI3G,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhE,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,MAAM,CAAC,MAAM,sBAAsB,GAAyB;IAC1D,IAAI,EAAE,kBAAkB,CAAC,cAAc;IAEvC,cAAc,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;QAC/D,IAAI,GAAG,IAAI,IAAI,kBAAkB,CAAC,cAAc,CAAA;QAChD,MA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AAC,IAAI,CAAwB,mBAAmB,CAAC,YAAY,EAAE;YACpF,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,SAAS,IAAI,EAAE;YAC7C,UAAU,EAAE,eAAe,GAAG,IAAI,CAAC,GAAG;YACtC,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,QAAQ,CAAC,KAAK;YACpB,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,CAAC,UAAU,CAAC;SACrB,CAAC,CAAA;QAEF,IAAI,IAAI,CAAC,KAAK,KAAK,mBAAmB,CAAC,aAAa,EAAE,CAAC;YACrD,IAAI,OAAO,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;gBAC7B,MAAM,IAAI,WAAW,CAAC,kEAAkE,CAAC,CAAA;YAC3F,CAAC;YACD,MAAM,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAA;QACxD,CAAC;QACD,SAAS;IACX,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;QAClB,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC3B,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { FC } from 'react';
2
+ import type { AuthenticationControl, AuthenticationRenderer, AuthenticationRendererProps } from '../components/authentication/types.js';
3
+ export interface AuthenticationPlugin extends Pick<AuthenticationControl, "beforeAuthenticate" | "afterAuthenticate">, Pick<Partial<AuthenticationControl>, "authenticate"> {
4
+ type: string;
5
+ Implementation: PluginImplemnetation;
6
+ Renderer?: AuthenticationRenderer;
7
+ }
8
+ export interface PluginImplemnetation {
9
+ (Renderer?: AuthenticationRenderer): FC<AuthenticationRendererProps>;
10
+ }
11
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/manager/plugins/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,2BAA2B,EAAG,MAAM,uCAAuC,CAAA;AAExI,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAChD,qBAAqB,EAAE,oBAAoB,GAAG,mBAAmB,CAClE,EAAE,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,cAAc,CAAC;IACrD,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,oBAAoB,CAAA;IACpC,QAAQ,CAAC,EAAE,sBAAsB,CAAA;CAClC;AAED,MAAM,WAAW,oBAAoB;IACnC,CAAC,QAAQ,CAAC,EAAE,sBAAsB,GAAG,EAAE,CAAC,2BAA2B,CAAC,CAAA;CACrE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/manager/plugins/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { ClientModule } from '@owlmeans/client-module';
2
+ export declare const modules: ClientModule[];
3
+ export declare const setupExternalAuthentication: (service: string) => void;
4
+ //# sourceMappingURL=modules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAI3D,eAAO,MAAM,OAAO,EAAE,YAAY,EAA2B,CAAA;AAE7D,eAAO,MAAM,2BAA2B,YAAa,MAAM,SAE1D,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { elevate, stab } from '@owlmeans/client-module';
2
+ import { modules as list } from '@owlmeans/auth-common';
3
+ import { CAUTHEN_FLOW_ENTER, DISPATCHER_AUTHEN } from '@owlmeans/auth';
4
+ elevate(list, DISPATCHER_AUTHEN);
5
+ export const modules = list;
6
+ export const setupExternalAuthentication = (service) => {
7
+ elevate(list, CAUTHEN_FLOW_ENTER, stab, { routeOptions: { overrides: { service } } });
8
+ };
9
+ //# sourceMappingURL=modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAGtE,OAAO,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;AAEhC,MAAM,CAAC,MAAM,OAAO,GAAmB,IAAsB,CAAA;AAE7D,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,OAAe,EAAE,EAAE;IAC7D,OAAO,CAAC,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAA;AACvF,CAAC,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { AuthServiceAppend } from './types.js';
2
+ import type { AuthService } from '@owlmeans/auth-common';
3
+ import type { ClientContext, ClientConfig } from '@owlmeans/client-context';
4
+ export declare const makeAuthService: (alias?: string) => AuthService;
5
+ export declare const appendAuthService: <C extends ClientConfig, T extends ClientContext<C>>(ctx: T, alias?: string) => T & AuthServiceAppend;
6
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAoB,MAAM,YAAY,CAAA;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGxD,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAO3E,eAAO,MAAM,eAAe,WAAW,MAAM,KAAmB,WA8E/D,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,aAAa,CAAC,CAAC,CAAC,OAC7E,CAAC,UAAS,MAAM,KACpB,CAAC,GAAG,iBAYN,CAAA"}
@@ -0,0 +1,71 @@
1
+ import { AUTH_RESOURCE, DEFAULT_ALIAS, USER_ID } from './consts.js';
2
+ import { assertContext, createService } from '@owlmeans/context';
3
+ import { AuthorizationError, DISPATCHER_AUTHEN } from '@owlmeans/auth';
4
+ import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope';
5
+ import { authMiddleware } from '@owlmeans/auth-common';
6
+ export const makeAuthService = (alias = DEFAULT_ALIAS) => {
7
+ const location = `auth-service:${alias}`;
8
+ const service = createService(alias, {
9
+ match: async () => service.authenticated() != null,
10
+ handle: async () => {
11
+ return void 0;
12
+ },
13
+ authenticate: async (token) => {
14
+ const context = assertContext(service.ctx, location);
15
+ const [authToken] = await context.module(DISPATCHER_AUTHEN)
16
+ .call({ body: token });
17
+ await service.update(authToken.token);
18
+ },
19
+ update: async (token) => {
20
+ service.token = token;
21
+ if (token == null) {
22
+ service.auth = undefined;
23
+ const authResource = service.store();
24
+ await authResource.delete(USER_ID);
25
+ return;
26
+ }
27
+ const authResource = service.store();
28
+ await authResource.save({ id: USER_ID, token });
29
+ const [, authorization] = token.split(' ');
30
+ const envelope = makeEnvelopeModel(authorization, EnvelopeKind.Token);
31
+ service.auth = envelope.message();
32
+ },
33
+ authenticated: async () => {
34
+ if (service.token == null) {
35
+ const authResource = service.store();
36
+ const record = await authResource.load(USER_ID);
37
+ if (record != null) {
38
+ const token = record.token;
39
+ if (token == '') {
40
+ service.token = undefined;
41
+ service.auth = undefined;
42
+ await authResource.delete(USER_ID);
43
+ return null;
44
+ }
45
+ const [, authorization] = token.split(' ');
46
+ service.token = token;
47
+ const envelope = makeEnvelopeModel(authorization, EnvelopeKind.Token);
48
+ service.auth = envelope.message();
49
+ }
50
+ }
51
+ return service.token ?? null;
52
+ },
53
+ user: () => {
54
+ if (service.auth == null) {
55
+ throw new AuthorizationError();
56
+ }
57
+ return service.auth;
58
+ },
59
+ store: () => service.assertCtx(location).resource(AUTH_RESOURCE)
60
+ });
61
+ return service;
62
+ };
63
+ export const appendAuthService = (ctx, alias = DEFAULT_ALIAS) => {
64
+ const service = makeAuthService(alias);
65
+ const context = ctx;
66
+ context.registerService(service);
67
+ context.registerMiddleware(authMiddleware);
68
+ context.auth = () => ctx.service(service.alias);
69
+ return context;
70
+ };
71
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEhE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAGtE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAgB,aAAa,EAAe,EAAE;IAC5E,MAAM,QAAQ,GAAG,gBAAgB,KAAK,EAAE,CAAA;IACxC,MAAM,OAAO,GAAgB,aAAa,CAAc,KAAK,EAAE;QAC7D,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,IAAI;QAElD,MAAM,EAAE,KAAK,IAAO,EAAE;YACpB,OAAO,KAAK,CAAM,CAAA;QACpB,CAAC;QAED,YAAY,EAAE,KAAK,EAAC,KAAK,EAAC,EAAE;YAC1B,MAAM,OAAO,GAAG,aA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,CAAC,cAAc,CAAC,CAAA;IAE1C,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAE/C,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
@@ -0,0 +1,13 @@
1
+ import type { ClientResource } from '@owlmeans/client-resource';
2
+ import type { ResourceRecord } from '@owlmeans/resource';
3
+ import type { AuthService } from '@owlmeans/auth-common';
4
+ export interface AuthServiceAppend {
5
+ auth: () => AuthService;
6
+ }
7
+ export interface ClientAuthRecord extends ResourceRecord {
8
+ token: string;
9
+ profileId?: string;
10
+ }
11
+ export interface ClientAuthResource extends ClientResource<ClientAuthRecord> {
12
+ }
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,WAAW,CAAA;CACxB;AAED,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,kBAAmB,SAAQ,cAAc,CAAC,gBAAgB,CAAC;CAC3E"}
package/build/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@owlmeans/client-auth",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "build": "tsc -b",
7
+ "dev": "sleep 66 && nodemon -e ts,tsx,json --watch src --exec \"tsc -p ./tsconfig.json\"",
8
+ "watch": "tsc -b -w --preserveWatchOutput --pretty"
9
+ },
10
+ "main": "build/index.js",
11
+ "module": "build/index.js",
12
+ "types": "build/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "import": "./build/index.js",
16
+ "require": "./build/index.js",
17
+ "default": "./build/index.js",
18
+ "module": "./build/index.js",
19
+ "types": "./build/index.d.ts"
20
+ },
21
+ "./manager": {
22
+ "import": "./build/manager/index.js",
23
+ "require": "./build/manager/index.js",
24
+ "default": "./build/manager/index.js",
25
+ "module": "./build/manager/index.js",
26
+ "types": "./build/manager/index.d.ts"
27
+ },
28
+ "./manager/modules": {
29
+ "import": "./build/manager/modules.js",
30
+ "require": "./build/manager/modules.js",
31
+ "default": "./build/manager/modules.js",
32
+ "module": "./build/manager/modules.js",
33
+ "types": "./build/manager/modules.d.ts"
34
+ },
35
+ "./manager/plugins": {
36
+ "import": "./build/manager/plugins/exports.js",
37
+ "require": "./build/manager/plugins/exports.js",
38
+ "default": "./build/manager/plugins/exports.js",
39
+ "module": "./build/manager/plugins/exports.js",
40
+ "types": "./build/manager/plugins/exports.d.ts"
41
+ }
42
+ },
43
+ "dependencies": {
44
+ "@owlmeans/auth": "^0.1.0",
45
+ "@owlmeans/auth-common": "^0.1.0",
46
+ "@owlmeans/basic-envelope": "^0.1.0",
47
+ "@owlmeans/basic-keys": "^0.1.0",
48
+ "@owlmeans/client": "^0.1.0",
49
+ "@owlmeans/client-context": "^0.1.0",
50
+ "@owlmeans/client-flow": "^0.1.0",
51
+ "@owlmeans/client-module": "^0.1.0",
52
+ "@owlmeans/client-resource": "^0.1.0",
53
+ "@owlmeans/client-socket": "^0.1.0",
54
+ "@owlmeans/context": "^0.1.0",
55
+ "@owlmeans/did": "^0.1.0",
56
+ "@owlmeans/error": "^0.1.0",
57
+ "@owlmeans/flow": "^0.1.0",
58
+ "@owlmeans/module": "^0.1.0",
59
+ "@owlmeans/resource": "^0.1.0",
60
+ "@owlmeans/socket": "^0.1.0",
61
+ "@owlmeans/web-flow": "^0.1.0",
62
+ "@scure/base": "^1.1.9"
63
+ },
64
+ "peerDependencies": {
65
+ "ajv": "*",
66
+ "react": "*",
67
+ "react-router": "*"
68
+ },
69
+ "devDependencies": {
70
+ "@types/react": "^18.3.11",
71
+ "nodemon": "^3.1.7",
72
+ "npm-check": "^6.0.1",
73
+ "typescript": "^5.6.3"
74
+ },
75
+ "private": false,
76
+ "publishConfig": {
77
+ "access": "public"
78
+ }
79
+ }