@secrecy/lib 1.59.4 → 1.60.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.
@@ -16,13 +16,15 @@ async function getPublicUser(client, id) {
16
16
  export class BaseClient {
17
17
  static getBaseClient = (opts = {}) => createTRPCClient(opts);
18
18
  client;
19
- authUrl;
20
- apiUrl;
19
+ secrecyUrls;
21
20
  sessionId;
22
21
  constructor(opts) {
23
22
  this.sessionId = opts.session;
24
- this.apiUrl = opts.apiUrl ?? 'https://api.secrecy.tech';
25
- this.authUrl = opts.authUrl ?? 'https://auth.secrecy.tech';
23
+ this.secrecyUrls = {
24
+ auth: opts.secrecyUrls?.auth ?? 'https://auth.secrecy.tech',
25
+ account: opts.secrecyUrls?.account ?? 'https://account.secrecy.tech',
26
+ api: opts.secrecyUrls?.api ?? 'https://api.secrecy.tech',
27
+ };
26
28
  this.client = BaseClient.getBaseClient({
27
29
  ...opts,
28
30
  onAccessDenied: async () => {
@@ -80,7 +82,7 @@ export class BaseClient {
80
82
  async getSponsorshipLink({ backUrl, }) {
81
83
  const me = await this.me();
82
84
  const hash = btoa(getPreferedEmail(me.account.emails)?.email);
83
- return `${this.authUrl}/sign-up/gf=${hash}&au=${btoa(backUrl)}`;
85
+ return `${this.secrecyUrls.auth}/sign-up/gf=${hash}&au=${btoa(backUrl)}`;
84
86
  }
85
87
  static getPaymentRequest = async ({ paymentRequestId, secrecyIdSeller, opts, }) => {
86
88
  const getPaymentRequestToPay = await BaseClient.getBaseClient(opts).stripe.paymentRequestToPay.query({
@@ -15,7 +15,7 @@ import { promiseAllLimit } from '../utils/promise.js';
15
15
  import { kiloToBytes } from '../utils.js';
16
16
  // import { md5 } from "../worker/index.js";
17
17
  // import { firstValueFrom, of } from "rxjs";
18
- import { fileTypeFromBlob, fileTypeFromBuffer } from 'file-type';
18
+ import { fileTypeFromBuffer } from 'file-type';
19
19
  export class SecrecyCloudClient {
20
20
  #client;
21
21
  #keys;
@@ -51,21 +51,17 @@ export class SecrecyCloudClient {
51
51
  return internalNodeFullToNodeFull(node);
52
52
  }
53
53
  async uploadData({ storageType, data, encrypted = true, encryptProgress, uploadProgress, signal, meta, }) {
54
+ const dataBuffer = data instanceof File ? new Uint8Array(await data.arrayBuffer()) : data;
54
55
  let filetype;
55
56
  if (meta === true) {
56
- filetype = await (data instanceof File
57
- ? fileTypeFromBlob(data)
58
- : fileTypeFromBuffer(data));
57
+ filetype = await fileTypeFromBuffer(dataBuffer);
59
58
  }
60
59
  else if (typeof meta !== 'undefined') {
61
60
  filetype = meta;
62
61
  }
63
62
  else if (!encrypted) {
64
- filetype = await (data instanceof File
65
- ? fileTypeFromBlob(data)
66
- : fileTypeFromBuffer(data));
63
+ filetype = await fileTypeFromBuffer(dataBuffer);
67
64
  }
68
- const dataBuffer = data instanceof File ? new Uint8Array(await data.arrayBuffer()) : data;
69
65
  if (storageType === 'lite' && dataBuffer.byteLength > kiloToBytes(1024)) {
70
66
  throw new Error('The data is too big for lite upload!');
71
67
  }
@@ -17,7 +17,7 @@ export class SecrecyPayClient {
17
17
  amount,
18
18
  currency,
19
19
  })).toString('base64');
20
- const url = `${this.#client.authUrl}/account/iframe/pay-confirm#${hash}`;
20
+ const url = `${this.#client.secrecyUrls.account}/iframe/pay-confirm#${hash}`;
21
21
  return await new Promise((resolve, reject) => popup(url, 'Secrecy Pay - Confirm Payment Intent', {
22
22
  width: 500,
23
23
  }, (err, data) => {
@@ -14,7 +14,7 @@ export class SecrecyWalletClient {
14
14
  network,
15
15
  tx,
16
16
  })).toString('base64');
17
- const url = `${this.#client.authUrl}/account/iframe/wallet-transaction#${hash}`;
17
+ const url = `${this.#client.secrecyUrls.account}/iframe/wallet-transaction#${hash}`;
18
18
  return await new Promise((resolve, reject) => popup(url, 'Secrecy Wallet - Transaction', {
19
19
  width: 500,
20
20
  }, (err, data) => {
@@ -31,7 +31,7 @@ export class SecrecyWalletClient {
31
31
  network,
32
32
  message,
33
33
  })).toString('base64');
34
- const url = `${this.#client.authUrl}/account/iframe/wallet-signature#${hash}`;
34
+ const url = `${this.#client.secrecyUrls.account}/iframe/wallet-signature#${hash}`;
35
35
  return await new Promise((resolve, reject) => popup(url, 'Secrecy Wallet - Signature', {
36
36
  width: 500,
37
37
  }, (err, data) => {
@@ -32,8 +32,7 @@ export function getSecrecyClient(opts = {}) {
32
32
  uaSession: infos.uaSession,
33
33
  uaKeys: infos.keys,
34
34
  uaJwt: infos.jwt,
35
- authUrl: opts.authUrl,
36
- apiUrl: opts.apiUrl,
35
+ secrecyUrls: opts.secrecyUrls,
37
36
  });
38
37
  }
39
38
  return null;
@@ -42,14 +41,13 @@ export function getSecrecyClient(opts = {}) {
42
41
  uaSession: uaSession,
43
42
  uaKeys: uaKeys,
44
43
  uaJwt: uaJwt,
45
- authUrl: opts.authUrl,
46
- apiUrl: opts.apiUrl,
44
+ secrecyUrls: opts.secrecyUrls,
47
45
  });
48
46
  }
49
- export async function login({ appId, path, redirect, scopes, backPath, session, apiUrl, authUrl, }) {
47
+ export async function login({ appId, path, redirect, scopes, backPath, session, secrecyUrls, }) {
50
48
  return await new Promise((resolve, reject) => {
51
49
  const appUrl = window.location.origin;
52
- const client = getSecrecyClient({ authUrl, apiUrl });
50
+ const client = getSecrecyClient({ secrecyUrls });
53
51
  if (client === null) {
54
52
  const infos = {
55
53
  appUrl,
@@ -60,6 +58,7 @@ export async function login({ appId, path, redirect, scopes, backPath, session,
60
58
  backPath,
61
59
  };
62
60
  const data = btoa(JSON.stringify(infos)).replaceAll('=', '');
61
+ const authUrl = secrecyUrls?.auth ?? 'https://auth.secrecy.tech';
63
62
  const url = `${authUrl}/login#${data}`;
64
63
  const validate = (infos) => {
65
64
  const storage = getStorage(session);
@@ -70,8 +69,7 @@ export async function login({ appId, path, redirect, scopes, backPath, session,
70
69
  uaSession: infos.uaSession,
71
70
  uaKeys: infos.keys,
72
71
  uaJwt: infos.jwt,
73
- authUrl: authUrl,
74
- apiUrl: apiUrl,
72
+ secrecyUrls,
75
73
  }));
76
74
  };
77
75
  if (redirect === true) {
@@ -29,8 +29,7 @@ export class SecrecyClient extends BaseClient {
29
29
  constructor(opts) {
30
30
  super({
31
31
  session: opts.uaSession,
32
- apiUrl: opts.apiUrl,
33
- authUrl: opts.authUrl,
32
+ secrecyUrls: opts.secrecyUrls,
34
33
  onAccessDenied: async () => {
35
34
  console.log('[CLIENT] - Access denied');
36
35
  try {
@@ -1,18 +1,21 @@
1
1
  import { type ApiClient, type RouterOutputs, type RouterInputs, CreateTrpcClientOptions } from './client.js';
2
2
  import { type InfuraNetwork, type PublicUser } from './index.js';
3
3
  import { type SelfUser } from './client/types/user.js';
4
+ export type SecrecyUrls = {
5
+ auth: string;
6
+ account: string;
7
+ api: string;
8
+ };
4
9
  export type BaseClientOptions = {
5
10
  session: string;
6
- authUrl?: string | null | undefined;
7
- apiUrl?: string | null | undefined;
8
11
  onAccessDenied?: () => void | Promise<void>;
12
+ secrecyUrls?: Partial<SecrecyUrls>;
9
13
  };
10
14
  export declare class BaseClient {
11
15
  #private;
12
16
  static readonly getBaseClient: (opts?: CreateTrpcClientOptions) => ApiClient;
13
17
  protected client: ApiClient;
14
- authUrl: string;
15
- apiUrl: string;
18
+ secrecyUrls: SecrecyUrls;
16
19
  sessionId: string;
17
20
  constructor(opts: BaseClientOptions);
18
21
  logout(sessionId?: string | null | undefined): Promise<void>;
@@ -1,5 +1,6 @@
1
1
  import { SecrecyClient } from './index.js';
2
2
  import { type SecrecyUserApp } from './types/index.js';
3
+ import type { SecrecyUrls } from '../base-client.js';
3
4
  export declare function parseInfos(): SecrecyUserApp | null;
4
5
  export interface HashInfos {
5
6
  appId: string;
@@ -13,16 +14,14 @@ export interface HashInfos {
13
14
  }
14
15
  export type UseSecrecyParams = Omit<HashInfos, 'appUrl'> & {
15
16
  session?: boolean | undefined;
16
- authUrl?: string | null | undefined;
17
- apiUrl?: string | null | undefined;
17
+ secrecyUrls?: Partial<SecrecyUrls>;
18
18
  };
19
19
  export declare function getSecrecyClient(opts?: {
20
20
  session?: boolean;
21
- authUrl?: string | null | undefined;
22
- apiUrl?: string | null | undefined;
21
+ secrecyUrls?: Partial<SecrecyUrls>;
23
22
  }): SecrecyClient | null;
24
23
  type LoginResponse<Params extends UseSecrecyParams> = Params extends {
25
24
  redirect: true;
26
25
  } ? SecrecyClient | null : SecrecyClient;
27
- export declare function login<Params extends UseSecrecyParams>({ appId, path, redirect, scopes, backPath, session, apiUrl, authUrl, }: Params): Promise<LoginResponse<Params>>;
26
+ export declare function login<Params extends UseSecrecyParams>({ appId, path, redirect, scopes, backPath, session, secrecyUrls, }: Params): Promise<LoginResponse<Params>>;
28
27
  export {};
@@ -1,4 +1,4 @@
1
- import { BaseClient } from '../base-client.js';
1
+ import { BaseClient, type SecrecyUrls } from '../base-client.js';
2
2
  import type { Progress } from '../crypto/data.js';
3
3
  import { SecrecyCloudClient } from './SecrecyCloudClient.js';
4
4
  import { SecrecyMailClient } from './SecrecyMailClient.js';
@@ -17,8 +17,7 @@ export interface SecrecyClientOptions {
17
17
  uaSession: string;
18
18
  uaKeys: KeyPair;
19
19
  uaJwt: string;
20
- authUrl?: string | null | undefined;
21
- apiUrl?: string | null | undefined;
20
+ secrecyUrls?: Partial<SecrecyUrls>;
22
21
  }
23
22
  export declare class SecrecyClient extends BaseClient {
24
23
  #private;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@secrecy/lib",
3
3
  "author": "Anonymize <anonymize@gmail.com>",
4
4
  "description": "Anonymize Secrecy Library",
5
- "version": "1.59.4",
5
+ "version": "1.60.0",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/anonymize-org/lib.git"
@@ -49,43 +49,43 @@
49
49
  "semantic-release": "semantic-release"
50
50
  },
51
51
  "devDependencies": {
52
- "@commitlint/cli": "^19.5.0",
53
- "@commitlint/config-conventional": "^19.5.0",
54
- "@prisma/client": "5.20.0",
55
- "@types/bun": "^1.1.10",
52
+ "@commitlint/cli": "^19.6.0",
53
+ "@commitlint/config-conventional": "^19.6.0",
54
+ "@prisma/client": "5.22.0",
55
+ "@types/bun": "^1.1.14",
56
56
  "@types/jsonwebtoken": "^9.0.7",
57
- "@types/spark-md5": "^3.0.4",
58
- "@typescript-eslint/eslint-plugin": "^8.7.0",
59
- "@typescript-eslint/parser": "^8.7.0",
60
- "eslint": "^9.11.1",
61
- "eslint-config-love": "^83.0.0",
57
+ "@types/spark-md5": "^3.0.5",
58
+ "@typescript-eslint/eslint-plugin": "^8.16.0",
59
+ "@typescript-eslint/parser": "^8.16.0",
60
+ "eslint": "^9.15.0",
61
+ "eslint-config-love": "^107.0.0",
62
62
  "eslint-config-prettier": "^9.1.0",
63
- "eslint-plugin-import": "^2.30.0",
64
- "eslint-plugin-n": "^17.10.3",
65
- "eslint-plugin-promise": "^7.1.0",
66
- "husky": "^9.1.6",
63
+ "eslint-plugin-import": "^2.31.0",
64
+ "eslint-plugin-n": "^17.14.0",
65
+ "eslint-plugin-promise": "^7.2.1",
66
+ "husky": "^9.1.7",
67
67
  "npm-run-all": "^4.1.5",
68
- "prettier": "^3.3.3",
68
+ "prettier": "^3.4.1",
69
69
  "rimraf": "^6.0.1",
70
- "semantic-release": "^24.1.1",
71
- "typedoc": "^0.26.7",
72
- "typedoc-plugin-markdown": "^4.2.8",
73
- "typedoc-plugin-missing-exports": "^3.0.0",
74
- "typescript": "^5.6.2"
70
+ "semantic-release": "^24.2.0",
71
+ "typedoc": "^0.27.0",
72
+ "typedoc-plugin-markdown": "^4.2.10",
73
+ "typedoc-plugin-missing-exports": "^3.1.0",
74
+ "typescript": "^5.7.2"
75
75
  },
76
76
  "dependencies": {
77
77
  "@secrecy/trpc-api-types": "1.33.0-dev.48",
78
78
  "@trpc/client": "10.45.2",
79
79
  "@trpc/server": "10.45.2",
80
80
  "@types/libsodium-wrappers-sumo": "^0.7.8",
81
- "axios": "^1.7.7",
82
- "bson": "^6.8.0",
83
- "ethers": "^6.13.2",
81
+ "axios": "^1.7.8",
82
+ "bson": "^6.10.0",
83
+ "ethers": "^6.13.4",
84
84
  "file-type": "^19.6.0",
85
85
  "jsonwebtoken": "^9.0.2",
86
86
  "ky": "^1.7.2",
87
87
  "libsodium-wrappers-sumo": "^0.7.15",
88
- "lru-cache": "^11.0.1",
88
+ "lru-cache": "^11.0.2",
89
89
  "spark-md5": "^3.0.2",
90
90
  "superjson": "2.2.1",
91
91
  "zod": "3.23.8"