@secrecy/lib 1.59.0 → 1.59.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.
- package/dist/lib/base-client.js +5 -4
- package/dist/lib/client/SecrecyPayClient.js +1 -1
- package/dist/lib/client/SecrecyWalletClient.js +2 -2
- package/dist/lib/client/helpers.js +25 -7
- package/dist/lib/client/index.js +6 -4
- package/dist/types/base-client.d.ts +4 -2
- package/dist/types/client/helpers.d.ts +8 -3
- package/dist/types/client/index.d.ts +8 -1
- package/package.json +1 -1
package/dist/lib/base-client.js
CHANGED
|
@@ -16,11 +16,13 @@ async function getPublicUser(client, id) {
|
|
|
16
16
|
export class BaseClient {
|
|
17
17
|
static getBaseClient = (opts = {}) => createTRPCClient(opts);
|
|
18
18
|
client;
|
|
19
|
-
|
|
19
|
+
authUrl;
|
|
20
|
+
apiUrl;
|
|
20
21
|
sessionId;
|
|
21
22
|
constructor(opts) {
|
|
22
23
|
this.sessionId = opts.session;
|
|
23
|
-
this.
|
|
24
|
+
this.apiUrl = opts.apiUrl ?? 'https://api.secrecy.tech';
|
|
25
|
+
this.authUrl = opts.authUrl ?? 'https://auth.secrecy.tech';
|
|
24
26
|
this.client = BaseClient.getBaseClient({
|
|
25
27
|
...opts,
|
|
26
28
|
onAccessDenied: async () => {
|
|
@@ -78,8 +80,7 @@ export class BaseClient {
|
|
|
78
80
|
async getSponsorshipLink({ backUrl, }) {
|
|
79
81
|
const me = await this.me();
|
|
80
82
|
const hash = btoa(getPreferedEmail(me.account.emails)?.email);
|
|
81
|
-
|
|
82
|
-
return `${authUrl}/sign-up/gf=${hash}&au=${btoa(backUrl)}`;
|
|
83
|
+
return `${this.authUrl}/sign-up/gf=${hash}&au=${btoa(backUrl)}`;
|
|
83
84
|
}
|
|
84
85
|
static getPaymentRequest = async ({ paymentRequestId, secrecyIdSeller, opts, }) => {
|
|
85
86
|
const getPaymentRequestToPay = await BaseClient.getBaseClient(opts).stripe.paymentRequestToPay.query({
|
|
@@ -17,7 +17,7 @@ export class SecrecyPayClient {
|
|
|
17
17
|
amount,
|
|
18
18
|
currency,
|
|
19
19
|
})).toString('base64');
|
|
20
|
-
const url = `${this.#client.
|
|
20
|
+
const url = `${this.#client.authUrl}/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.
|
|
17
|
+
const url = `${this.#client.authUrl}/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.
|
|
34
|
+
const url = `${this.#client.authUrl}/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) => {
|
|
@@ -17,8 +17,8 @@ export function parseInfos() {
|
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
export function getSecrecyClient(
|
|
21
|
-
const storage = getStorage(session);
|
|
20
|
+
export function getSecrecyClient(opts = {}) {
|
|
21
|
+
const storage = getStorage(opts.session);
|
|
22
22
|
const uaSession = storage.userAppSession.load();
|
|
23
23
|
const uaKeys = storage.userAppKeys.load();
|
|
24
24
|
const uaJwt = storage.jwt.load();
|
|
@@ -28,16 +28,28 @@ export function getSecrecyClient(session) {
|
|
|
28
28
|
storage.userAppKeys.save(infos.keys);
|
|
29
29
|
storage.userAppSession.save(infos.uaSession);
|
|
30
30
|
storage.jwt.save(infos.jwt);
|
|
31
|
-
return new SecrecyClient(
|
|
31
|
+
return new SecrecyClient({
|
|
32
|
+
uaSession: infos.uaSession,
|
|
33
|
+
uaKeys: infos.keys,
|
|
34
|
+
uaJwt: infos.jwt,
|
|
35
|
+
authUrl: opts.authUrl,
|
|
36
|
+
apiUrl: opts.apiUrl,
|
|
37
|
+
});
|
|
32
38
|
}
|
|
33
39
|
return null;
|
|
34
40
|
}
|
|
35
|
-
return new SecrecyClient(
|
|
41
|
+
return new SecrecyClient({
|
|
42
|
+
uaSession: uaSession,
|
|
43
|
+
uaKeys: uaKeys,
|
|
44
|
+
uaJwt: uaJwt,
|
|
45
|
+
authUrl: opts.authUrl,
|
|
46
|
+
apiUrl: opts.apiUrl,
|
|
47
|
+
});
|
|
36
48
|
}
|
|
37
|
-
export async function login({ appId, path, redirect, scopes, backPath, session, authUrl
|
|
49
|
+
export async function login({ appId, path, redirect, scopes, backPath, session, apiUrl, authUrl, }) {
|
|
38
50
|
return await new Promise((resolve, reject) => {
|
|
39
51
|
const appUrl = window.location.origin;
|
|
40
|
-
const client = getSecrecyClient();
|
|
52
|
+
const client = getSecrecyClient({ authUrl, apiUrl });
|
|
41
53
|
if (client === null) {
|
|
42
54
|
const infos = {
|
|
43
55
|
appUrl,
|
|
@@ -54,7 +66,13 @@ export async function login({ appId, path, redirect, scopes, backPath, session,
|
|
|
54
66
|
storage.userAppSession.save(infos.uaSession);
|
|
55
67
|
storage.userAppKeys.save(infos.keys);
|
|
56
68
|
storage.jwt.save(infos.jwt);
|
|
57
|
-
resolve(new SecrecyClient(
|
|
69
|
+
resolve(new SecrecyClient({
|
|
70
|
+
uaSession: infos.uaSession,
|
|
71
|
+
uaKeys: infos.keys,
|
|
72
|
+
uaJwt: infos.jwt,
|
|
73
|
+
authUrl: authUrl,
|
|
74
|
+
apiUrl: apiUrl,
|
|
75
|
+
}));
|
|
58
76
|
};
|
|
59
77
|
if (redirect === true) {
|
|
60
78
|
const infos = parseInfos();
|
package/dist/lib/client/index.js
CHANGED
|
@@ -26,9 +26,11 @@ export class SecrecyClient extends BaseClient {
|
|
|
26
26
|
pay;
|
|
27
27
|
user;
|
|
28
28
|
pseudonym;
|
|
29
|
-
constructor(
|
|
29
|
+
constructor(opts) {
|
|
30
30
|
super({
|
|
31
|
-
session: uaSession,
|
|
31
|
+
session: opts.uaSession,
|
|
32
|
+
apiUrl: opts.apiUrl,
|
|
33
|
+
authUrl: opts.authUrl,
|
|
32
34
|
onAccessDenied: async () => {
|
|
33
35
|
console.log('[CLIENT] - Access denied');
|
|
34
36
|
try {
|
|
@@ -39,10 +41,10 @@ export class SecrecyClient extends BaseClient {
|
|
|
39
41
|
}
|
|
40
42
|
},
|
|
41
43
|
});
|
|
42
|
-
this.#keys = uaKeys;
|
|
44
|
+
this.#keys = opts.uaKeys;
|
|
43
45
|
this.cloud = new SecrecyCloudClient(this, this.#keys, this.client);
|
|
44
46
|
this.mail = new SecrecyMailClient(this, this.#keys, this.client);
|
|
45
|
-
this.app = new SecrecyAppClient(uaJwt, this, this.#keys, this.client);
|
|
47
|
+
this.app = new SecrecyAppClient(opts.uaJwt, this, this.#keys, this.client);
|
|
46
48
|
this.db = new SecrecyDbClient(this, this.#keys, this.client);
|
|
47
49
|
this.wallet = new SecrecyWalletClient(this);
|
|
48
50
|
this.pay = new SecrecyPayClient(this, this.#keys, this.client);
|
|
@@ -3,14 +3,16 @@ import { type InfuraNetwork, type PublicUser } from './index.js';
|
|
|
3
3
|
import { type SelfUser } from './client/types/user.js';
|
|
4
4
|
export type BaseClientOptions = {
|
|
5
5
|
session: string;
|
|
6
|
-
|
|
6
|
+
authUrl?: string | null | undefined;
|
|
7
|
+
apiUrl?: string | null | undefined;
|
|
7
8
|
onAccessDenied?: () => void | Promise<void>;
|
|
8
9
|
};
|
|
9
10
|
export declare class BaseClient {
|
|
10
11
|
#private;
|
|
11
12
|
static readonly getBaseClient: (opts?: CreateTrpcClientOptions) => ApiClient;
|
|
12
13
|
protected client: ApiClient;
|
|
13
|
-
|
|
14
|
+
authUrl: string;
|
|
15
|
+
apiUrl: string;
|
|
14
16
|
sessionId: string;
|
|
15
17
|
constructor(opts: BaseClientOptions);
|
|
16
18
|
logout(sessionId?: string | null | undefined): Promise<void>;
|
|
@@ -4,7 +4,6 @@ export declare function parseInfos(): SecrecyUserApp | null;
|
|
|
4
4
|
export interface HashInfos {
|
|
5
5
|
appId: string;
|
|
6
6
|
appUrl: string;
|
|
7
|
-
authUrl?: string;
|
|
8
7
|
backPath?: string;
|
|
9
8
|
path?: string | null | undefined;
|
|
10
9
|
redirect?: boolean;
|
|
@@ -14,10 +13,16 @@ export interface HashInfos {
|
|
|
14
13
|
}
|
|
15
14
|
export type UseSecrecyParams = Omit<HashInfos, 'appUrl'> & {
|
|
16
15
|
session?: boolean | undefined;
|
|
16
|
+
authUrl?: string | null | undefined;
|
|
17
|
+
apiUrl?: string | null | undefined;
|
|
17
18
|
};
|
|
18
|
-
export declare function getSecrecyClient(
|
|
19
|
+
export declare function getSecrecyClient(opts?: {
|
|
20
|
+
session?: boolean;
|
|
21
|
+
authUrl?: string | null | undefined;
|
|
22
|
+
apiUrl?: string | null | undefined;
|
|
23
|
+
}): SecrecyClient | null;
|
|
19
24
|
type LoginResponse<Params extends UseSecrecyParams> = Params extends {
|
|
20
25
|
redirect: true;
|
|
21
26
|
} ? SecrecyClient | null : SecrecyClient;
|
|
22
|
-
export declare function login<Params extends UseSecrecyParams>({ appId, path, redirect, scopes, backPath, session, authUrl, }: Params): Promise<LoginResponse<Params>>;
|
|
27
|
+
export declare function login<Params extends UseSecrecyParams>({ appId, path, redirect, scopes, backPath, session, apiUrl, authUrl, }: Params): Promise<LoginResponse<Params>>;
|
|
23
28
|
export {};
|
|
@@ -13,6 +13,13 @@ import { SecrecyPseudonymClient } from './SecrecyPseudonymClient.js';
|
|
|
13
13
|
export type NewMail = Pick<RouterInputs['mail']['createDraft'], 'body' | 'subject' | 'senderFiles' | 'recipients' | 'replyToId'>;
|
|
14
14
|
export type ProgressCallback = (progress: Progress) => Promise<void>;
|
|
15
15
|
export declare const encryptName: (name: string, nameKey: string) => Promise<string>;
|
|
16
|
+
export interface SecrecyClientOptions {
|
|
17
|
+
uaSession: string;
|
|
18
|
+
uaKeys: KeyPair;
|
|
19
|
+
uaJwt: string;
|
|
20
|
+
authUrl?: string | null | undefined;
|
|
21
|
+
apiUrl?: string | null | undefined;
|
|
22
|
+
}
|
|
16
23
|
export declare class SecrecyClient extends BaseClient {
|
|
17
24
|
#private;
|
|
18
25
|
cloud: SecrecyCloudClient;
|
|
@@ -23,7 +30,7 @@ export declare class SecrecyClient extends BaseClient {
|
|
|
23
30
|
pay: SecrecyPayClient;
|
|
24
31
|
user: SecrecyUserClient;
|
|
25
32
|
pseudonym: SecrecyPseudonymClient;
|
|
26
|
-
constructor(
|
|
33
|
+
constructor(opts: SecrecyClientOptions);
|
|
27
34
|
get publicKey(): string;
|
|
28
35
|
decryptAnonymous(data: Uint8Array): Uint8Array;
|
|
29
36
|
logout(sessionId?: string | null | undefined): Promise<void>;
|
package/package.json
CHANGED