@ledgerhq/live-wallet 0.2.0 → 0.2.1-nightly.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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +1 -0
- package/CHANGELOG.md +19 -0
- package/lib/cloudsync/api.d.ts +75 -0
- package/lib/cloudsync/api.d.ts.map +1 -0
- package/lib/cloudsync/api.js +112 -0
- package/lib/cloudsync/api.js.map +1 -0
- package/lib/cloudsync/datatypes/live.d.ts +93 -0
- package/lib/cloudsync/datatypes/live.d.ts.map +1 -0
- package/lib/cloudsync/datatypes/live.js +19 -0
- package/lib/cloudsync/datatypes/live.js.map +1 -0
- package/lib/cloudsync/index.d.ts +4 -0
- package/lib/cloudsync/index.d.ts.map +1 -0
- package/lib/cloudsync/index.js +21 -0
- package/lib/cloudsync/index.js.map +1 -0
- package/lib/cloudsync/sdk.d.ts +51 -0
- package/lib/cloudsync/sdk.d.ts.map +1 -0
- package/lib/cloudsync/sdk.js +131 -0
- package/lib/cloudsync/sdk.js.map +1 -0
- package/lib/store.d.ts.map +1 -1
- package/lib/store.js +10 -2
- package/lib/store.js.map +1 -1
- package/lib-es/cloudsync/api.d.ts +75 -0
- package/lib-es/cloudsync/api.d.ts.map +1 -0
- package/lib-es/cloudsync/api.js +107 -0
- package/lib-es/cloudsync/api.js.map +1 -0
- package/lib-es/cloudsync/datatypes/live.d.ts +93 -0
- package/lib-es/cloudsync/datatypes/live.d.ts.map +1 -0
- package/lib-es/cloudsync/datatypes/live.js +16 -0
- package/lib-es/cloudsync/datatypes/live.js.map +1 -0
- package/lib-es/cloudsync/index.d.ts +4 -0
- package/lib-es/cloudsync/index.d.ts.map +1 -0
- package/lib-es/cloudsync/index.js +3 -0
- package/lib-es/cloudsync/index.js.map +1 -0
- package/lib-es/cloudsync/sdk.d.ts +51 -0
- package/lib-es/cloudsync/sdk.d.ts.map +1 -0
- package/lib-es/cloudsync/sdk.js +124 -0
- package/lib-es/cloudsync/sdk.js.map +1 -0
- package/lib-es/store.d.ts.map +1 -1
- package/lib-es/store.js +10 -2
- package/lib-es/store.js.map +1 -1
- package/package.json +17 -10
- package/src/cloudsync/api.ts +110 -0
- package/src/cloudsync/datatypes/live.ts +21 -0
- package/src/cloudsync/index.ts +3 -0
- package/src/cloudsync/sdk.ts +158 -0
- package/src/store.ts +9 -2
package/.turbo/turbo-build.log
CHANGED
package/.unimportedrc.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ledgerhq/live-wallet
|
|
2
2
|
|
|
3
|
+
## 0.2.1-nightly.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`fe8a26b`](https://github.com/LedgerHQ/ledger-live/commit/fe8a26b04206df64e50220c3e9249c9a1bd057a6)]:
|
|
8
|
+
- @ledgerhq/cryptoassets@13.1.1-nightly.0
|
|
9
|
+
- @ledgerhq/coin-framework@0.14.1-nightly.1
|
|
10
|
+
|
|
11
|
+
## 0.2.1-nightly.0
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`1cbf767`](https://github.com/LedgerHQ/ledger-live/commit/1cbf767465d9e1f7bed5de79c5b5a0a5ca06e1b5)]:
|
|
16
|
+
- @ledgerhq/types-live@6.48.1-nightly.0
|
|
17
|
+
- @ledgerhq/coin-framework@0.14.1-nightly.0
|
|
18
|
+
- @ledgerhq/devices@8.4.1-nightly.0
|
|
19
|
+
- @ledgerhq/live-network@1.3.1-nightly.0
|
|
20
|
+
- @ledgerhq/trustchain@0.1.2-nightly.0
|
|
21
|
+
|
|
3
22
|
## 0.2.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
export type JWT = {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
};
|
|
6
|
+
declare const schemaAtomicGetResponse: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
|
|
7
|
+
status: z.ZodLiteral<"no-data">;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
status: "no-data";
|
|
10
|
+
}, {
|
|
11
|
+
status: "no-data";
|
|
12
|
+
}>, z.ZodObject<{
|
|
13
|
+
status: z.ZodLiteral<"up-to-date">;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
status: "up-to-date";
|
|
16
|
+
}, {
|
|
17
|
+
status: "up-to-date";
|
|
18
|
+
}>, z.ZodObject<{
|
|
19
|
+
status: z.ZodLiteral<"out-of-sync">;
|
|
20
|
+
version: z.ZodNumber;
|
|
21
|
+
payload: z.ZodString;
|
|
22
|
+
date: z.ZodString;
|
|
23
|
+
info: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
payload: string;
|
|
26
|
+
status: "out-of-sync";
|
|
27
|
+
date: string;
|
|
28
|
+
version: number;
|
|
29
|
+
info?: string | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
payload: string;
|
|
32
|
+
status: "out-of-sync";
|
|
33
|
+
date: string;
|
|
34
|
+
version: number;
|
|
35
|
+
info?: string | undefined;
|
|
36
|
+
}>]>;
|
|
37
|
+
export type APISyncResponse = z.infer<typeof schemaAtomicGetResponse>;
|
|
38
|
+
declare const schemaAtomicPostResponse: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
|
|
39
|
+
status: z.ZodLiteral<"updated">;
|
|
40
|
+
}, "strip", z.ZodTypeAny, {
|
|
41
|
+
status: "updated";
|
|
42
|
+
}, {
|
|
43
|
+
status: "updated";
|
|
44
|
+
}>, z.ZodObject<{
|
|
45
|
+
status: z.ZodLiteral<"out-of-sync">;
|
|
46
|
+
version: z.ZodNumber;
|
|
47
|
+
payload: z.ZodString;
|
|
48
|
+
date: z.ZodString;
|
|
49
|
+
info: z.ZodOptional<z.ZodString>;
|
|
50
|
+
}, "strip", z.ZodTypeAny, {
|
|
51
|
+
payload: string;
|
|
52
|
+
status: "out-of-sync";
|
|
53
|
+
date: string;
|
|
54
|
+
version: number;
|
|
55
|
+
info?: string | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
payload: string;
|
|
58
|
+
status: "out-of-sync";
|
|
59
|
+
date: string;
|
|
60
|
+
version: number;
|
|
61
|
+
info?: string | undefined;
|
|
62
|
+
}>]>;
|
|
63
|
+
export type APISyncUpdateResponse = z.infer<typeof schemaAtomicPostResponse>;
|
|
64
|
+
declare function fetchData(jwt: JWT, datatype: string, version?: number): Promise<APISyncResponse>;
|
|
65
|
+
declare function uploadData(jwt: JWT, datatype: string, version: number, payload: string): Promise<APISyncUpdateResponse>;
|
|
66
|
+
declare function deleteData(jwt: JWT, datatype: string): Promise<void>;
|
|
67
|
+
declare function listenNotifications(jwt: JWT, datatype: string): Observable<number>;
|
|
68
|
+
declare const _default: {
|
|
69
|
+
fetchData: typeof fetchData;
|
|
70
|
+
uploadData: typeof uploadData;
|
|
71
|
+
deleteData: typeof deleteData;
|
|
72
|
+
listenNotifications: typeof listenNotifications;
|
|
73
|
+
};
|
|
74
|
+
export default _default;
|
|
75
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/cloudsync/api.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAIpB,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,MAAM,MAAM,GAAG,GAAG;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAeF,QAAA,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAI3B,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAYtE,QAAA,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;IAG5B,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAG7E,iBAAe,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAU/F;AAGD,iBAAe,UAAU,CACvB,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,qBAAqB,CAAC,CAahC;AAGD,iBAAe,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQnE;AAED,iBAAS,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAU3E;;;;;;;AAED,wBAKE"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const zod_1 = __importDefault(require("zod"));
|
|
16
|
+
const live_network_1 = __importDefault(require("@ledgerhq/live-network"));
|
|
17
|
+
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
18
|
+
const live_env_1 = require("@ledgerhq/live-env");
|
|
19
|
+
const rxjs_1 = require("rxjs");
|
|
20
|
+
const schemaAtomicGetNoData = zod_1.default.object({
|
|
21
|
+
status: zod_1.default.literal("no-data"),
|
|
22
|
+
});
|
|
23
|
+
const schemaAtomicGetUpToDate = zod_1.default.object({
|
|
24
|
+
status: zod_1.default.literal("up-to-date"),
|
|
25
|
+
});
|
|
26
|
+
const schemaAtomicGetOutOfSync = zod_1.default.object({
|
|
27
|
+
status: zod_1.default.literal("out-of-sync"),
|
|
28
|
+
version: zod_1.default.number(),
|
|
29
|
+
payload: zod_1.default.string(),
|
|
30
|
+
date: zod_1.default.string(),
|
|
31
|
+
info: zod_1.default.string().optional(),
|
|
32
|
+
});
|
|
33
|
+
const schemaAtomicGetResponse = zod_1.default.discriminatedUnion("status", [
|
|
34
|
+
schemaAtomicGetNoData,
|
|
35
|
+
schemaAtomicGetUpToDate,
|
|
36
|
+
schemaAtomicGetOutOfSync,
|
|
37
|
+
]);
|
|
38
|
+
const schemaAtomicPostUpdated = zod_1.default.object({
|
|
39
|
+
status: zod_1.default.literal("updated"),
|
|
40
|
+
});
|
|
41
|
+
const schemaAtomicPostOutOfSync = zod_1.default.object({
|
|
42
|
+
status: zod_1.default.literal("out-of-sync"),
|
|
43
|
+
version: zod_1.default.number(),
|
|
44
|
+
payload: zod_1.default.string(),
|
|
45
|
+
date: zod_1.default.string(),
|
|
46
|
+
info: zod_1.default.string().optional(),
|
|
47
|
+
});
|
|
48
|
+
const schemaAtomicPostResponse = zod_1.default.discriminatedUnion("status", [
|
|
49
|
+
schemaAtomicPostUpdated,
|
|
50
|
+
schemaAtomicPostOutOfSync,
|
|
51
|
+
]);
|
|
52
|
+
// Fetch data status from cloud
|
|
53
|
+
function fetchData(jwt, datatype, version) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const { data } = yield (0, live_network_1.default)({
|
|
56
|
+
url: `${(0, live_env_1.getEnv)("CLOUD_SYNC_API")}/atomic/v1/${datatype}`,
|
|
57
|
+
method: "GET",
|
|
58
|
+
headers: {
|
|
59
|
+
Authorization: `Bearer ${jwt.accessToken}`,
|
|
60
|
+
},
|
|
61
|
+
params: version !== undefined ? { version } : {},
|
|
62
|
+
});
|
|
63
|
+
return schemaAtomicGetResponse.parse(data);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// Upload new version of data to cloud
|
|
67
|
+
function uploadData(jwt, datatype, version, payload) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const { data } = yield (0, live_network_1.default)({
|
|
70
|
+
url: `${(0, live_env_1.getEnv)("CLOUD_SYNC_API")}/atomic/v1/${datatype}?version=${version}`,
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: {
|
|
73
|
+
Authorization: `Bearer ${jwt.accessToken}`,
|
|
74
|
+
"Content-Type": "application/json",
|
|
75
|
+
},
|
|
76
|
+
data: {
|
|
77
|
+
payload,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
return schemaAtomicPostResponse.parse(data);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// Delete data from cloud
|
|
84
|
+
function deleteData(jwt, datatype) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
yield (0, live_network_1.default)({
|
|
87
|
+
url: `${(0, live_env_1.getEnv)("CLOUD_SYNC_API")}/atomic/v1/${datatype}`,
|
|
88
|
+
method: "DELETE",
|
|
89
|
+
headers: {
|
|
90
|
+
Authorization: `Bearer ${jwt.accessToken}`,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function listenNotifications(jwt, datatype) {
|
|
96
|
+
const url = `${(0, live_env_1.getEnv)("CLOUD_SYNC_API").replace("http", "ws")}/atomic/v1/${datatype}/notifications`;
|
|
97
|
+
const ws = new isomorphic_ws_1.default(url);
|
|
98
|
+
return new rxjs_1.Observable(observer => {
|
|
99
|
+
ws.addEventListener("message", (e) => observer.next(parseInt(e.data, 10)));
|
|
100
|
+
ws.addEventListener("close", () => observer.complete());
|
|
101
|
+
ws.addEventListener("error", error => observer.error(error));
|
|
102
|
+
ws.addEventListener("open", () => ws.send(jwt.accessToken));
|
|
103
|
+
return () => ws.close();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
exports.default = {
|
|
107
|
+
fetchData,
|
|
108
|
+
uploadData,
|
|
109
|
+
deleteData,
|
|
110
|
+
listenNotifications,
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/cloudsync/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,8CAAoB;AACpB,0EAA6C;AAC7C,kEAA+B;AAC/B,iDAA4C;AAC5C,+BAAkC;AAMlC,MAAM,qBAAqB,GAAG,aAAC,CAAC,MAAM,CAAC;IACrC,MAAM,EAAE,aAAC,CAAC,OAAO,CAAC,SAAS,CAAC;CAC7B,CAAC,CAAC;AACH,MAAM,uBAAuB,GAAG,aAAC,CAAC,MAAM,CAAC;IACvC,MAAM,EAAE,aAAC,CAAC,OAAO,CAAC,YAAY,CAAC;CAChC,CAAC,CAAC;AACH,MAAM,wBAAwB,GAAG,aAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,aAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAChC,OAAO,EAAE,aAAC,CAAC,MAAM,EAAE;IACnB,OAAO,EAAE,aAAC,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,aAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,aAAC,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,CAAC;QACzF,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxD,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7D,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;QAC5D,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,kBAAe;IACb,SAAS;IACT,UAAU;IACV,UAAU;IACV,mBAAmB;CACpB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const accountDescriptorSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
currencyId: z.ZodString;
|
|
5
|
+
freshAddress: z.ZodString;
|
|
6
|
+
seedIdentifier: z.ZodString;
|
|
7
|
+
derivationMode: z.ZodString;
|
|
8
|
+
index: z.ZodNumber;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
index: number;
|
|
11
|
+
id: string;
|
|
12
|
+
seedIdentifier: string;
|
|
13
|
+
derivationMode: string;
|
|
14
|
+
freshAddress: string;
|
|
15
|
+
currencyId: string;
|
|
16
|
+
}, {
|
|
17
|
+
index: number;
|
|
18
|
+
id: string;
|
|
19
|
+
seedIdentifier: string;
|
|
20
|
+
derivationMode: string;
|
|
21
|
+
freshAddress: string;
|
|
22
|
+
currencyId: string;
|
|
23
|
+
}>;
|
|
24
|
+
export type AccountDescriptor = z.infer<typeof accountDescriptorSchema>;
|
|
25
|
+
export declare const accountsDescriptorSchema: z.ZodArray<z.ZodObject<{
|
|
26
|
+
id: z.ZodString;
|
|
27
|
+
currencyId: z.ZodString;
|
|
28
|
+
freshAddress: z.ZodString;
|
|
29
|
+
seedIdentifier: z.ZodString;
|
|
30
|
+
derivationMode: z.ZodString;
|
|
31
|
+
index: z.ZodNumber;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
index: number;
|
|
34
|
+
id: string;
|
|
35
|
+
seedIdentifier: string;
|
|
36
|
+
derivationMode: string;
|
|
37
|
+
freshAddress: string;
|
|
38
|
+
currencyId: string;
|
|
39
|
+
}, {
|
|
40
|
+
index: number;
|
|
41
|
+
id: string;
|
|
42
|
+
seedIdentifier: string;
|
|
43
|
+
derivationMode: string;
|
|
44
|
+
freshAddress: string;
|
|
45
|
+
currencyId: string;
|
|
46
|
+
}>, "many">;
|
|
47
|
+
export declare const liveSchema: z.ZodObject<{
|
|
48
|
+
accounts: z.ZodArray<z.ZodObject<{
|
|
49
|
+
id: z.ZodString;
|
|
50
|
+
currencyId: z.ZodString;
|
|
51
|
+
freshAddress: z.ZodString;
|
|
52
|
+
seedIdentifier: z.ZodString;
|
|
53
|
+
derivationMode: z.ZodString;
|
|
54
|
+
index: z.ZodNumber;
|
|
55
|
+
}, "strip", z.ZodTypeAny, {
|
|
56
|
+
index: number;
|
|
57
|
+
id: string;
|
|
58
|
+
seedIdentifier: string;
|
|
59
|
+
derivationMode: string;
|
|
60
|
+
freshAddress: string;
|
|
61
|
+
currencyId: string;
|
|
62
|
+
}, {
|
|
63
|
+
index: number;
|
|
64
|
+
id: string;
|
|
65
|
+
seedIdentifier: string;
|
|
66
|
+
derivationMode: string;
|
|
67
|
+
freshAddress: string;
|
|
68
|
+
currencyId: string;
|
|
69
|
+
}>, "many">;
|
|
70
|
+
accountNames: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
71
|
+
}, "strip", z.ZodTypeAny, {
|
|
72
|
+
accountNames: Record<string, string>;
|
|
73
|
+
accounts: {
|
|
74
|
+
index: number;
|
|
75
|
+
id: string;
|
|
76
|
+
seedIdentifier: string;
|
|
77
|
+
derivationMode: string;
|
|
78
|
+
freshAddress: string;
|
|
79
|
+
currencyId: string;
|
|
80
|
+
}[];
|
|
81
|
+
}, {
|
|
82
|
+
accountNames: Record<string, string>;
|
|
83
|
+
accounts: {
|
|
84
|
+
index: number;
|
|
85
|
+
id: string;
|
|
86
|
+
seedIdentifier: string;
|
|
87
|
+
derivationMode: string;
|
|
88
|
+
freshAddress: string;
|
|
89
|
+
currencyId: string;
|
|
90
|
+
}[];
|
|
91
|
+
}>;
|
|
92
|
+
export type LiveData = z.infer<typeof liveSchema>;
|
|
93
|
+
//# sourceMappingURL=live.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live.d.ts","sourceRoot":"","sources":["../../../src/cloudsync/datatypes/live.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;EAOlC,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;WAAmC,CAAC;AAEzE,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIrB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.liveSchema = exports.accountsDescriptorSchema = exports.accountDescriptorSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.accountDescriptorSchema = zod_1.z.object({
|
|
6
|
+
id: zod_1.z.string(),
|
|
7
|
+
currencyId: zod_1.z.string(),
|
|
8
|
+
freshAddress: zod_1.z.string(),
|
|
9
|
+
seedIdentifier: zod_1.z.string(),
|
|
10
|
+
derivationMode: zod_1.z.string(),
|
|
11
|
+
index: zod_1.z.number(),
|
|
12
|
+
});
|
|
13
|
+
exports.accountsDescriptorSchema = zod_1.z.array(exports.accountDescriptorSchema);
|
|
14
|
+
exports.liveSchema = zod_1.z.object({
|
|
15
|
+
accounts: exports.accountsDescriptorSchema,
|
|
16
|
+
accountNames: zod_1.z.record(zod_1.z.string()),
|
|
17
|
+
// NB: append more fields here when we have more needs in the future, but NEVER break a type
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=live.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live.js","sourceRoot":"","sources":["../../../src/cloudsync/datatypes/live.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAEX,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9C,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE;IACd,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;IACtB,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE;IACxB,cAAc,EAAE,OAAC,CAAC,MAAM,EAAE;IAC1B,cAAc,EAAE,OAAC,CAAC,MAAM,EAAE;IAC1B,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;CAClB,CAAC,CAAC;AAGU,QAAA,wBAAwB,GAAG,OAAC,CAAC,KAAK,CAAC,+BAAuB,CAAC,CAAC;AAE5D,QAAA,UAAU,GAAG,OAAC,CAAC,MAAM,CAAC;IACjC,QAAQ,EAAE,gCAAwB;IAClC,YAAY,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;IAClC,4FAA4F;CAC7F,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cloudsync/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.liveSchema = void 0;
|
|
18
|
+
__exportStar(require("./sdk"), exports);
|
|
19
|
+
var live_1 = require("./datatypes/live");
|
|
20
|
+
Object.defineProperty(exports, "liveSchema", { enumerable: true, get: function () { return live_1.liveSchema; } });
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cloudsync/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,yCAA8C;AAArC,kGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Trustchain, TrustchainSDK } from "@ledgerhq/trustchain/types";
|
|
2
|
+
import { LiveData } from "./datatypes/live";
|
|
3
|
+
import { JWT } from "./api";
|
|
4
|
+
import { Observable } from "rxjs";
|
|
5
|
+
export type UpdateEvent = {
|
|
6
|
+
type: "new-data";
|
|
7
|
+
data: LiveData;
|
|
8
|
+
version: number;
|
|
9
|
+
} | {
|
|
10
|
+
type: "pushed-data";
|
|
11
|
+
version: number;
|
|
12
|
+
} | {
|
|
13
|
+
type: "deleted-data";
|
|
14
|
+
};
|
|
15
|
+
export declare class CloudSyncSDK {
|
|
16
|
+
trustchainSdk: TrustchainSDK;
|
|
17
|
+
getCurrentVersion: () => number | undefined;
|
|
18
|
+
saveNewUpdate: (updateEvent: UpdateEvent) => Promise<void>;
|
|
19
|
+
constructor({ trustchainSdk, getCurrentVersion, saveNewUpdate, }: {
|
|
20
|
+
trustchainSdk: TrustchainSDK;
|
|
21
|
+
/**
|
|
22
|
+
* returns the current version of the data, if available.
|
|
23
|
+
*/
|
|
24
|
+
getCurrentVersion: () => number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* apply the data over the accounts and we also save the version.
|
|
27
|
+
* All the reconciliation and async save can be performed at this step in order to guarantee atomicity of the operations.
|
|
28
|
+
*/
|
|
29
|
+
saveNewUpdate: (event: UpdateEvent) => Promise<void>;
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Push new data to the Cloud Sync backend.
|
|
33
|
+
* Will fails if the version is out of sync. (conflicts)
|
|
34
|
+
*/
|
|
35
|
+
push(jwt: JWT, trustchain: Trustchain, data: LiveData): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Pull new data from the Cloud Sync backend, if any.
|
|
38
|
+
* If new data is retrieved, it will be decrypted and saveNewUpdate will be called as part of this atomic process.
|
|
39
|
+
*/
|
|
40
|
+
pull(jwt: JWT, trustchain: Trustchain): Promise<void>;
|
|
41
|
+
destroy(jwt: JWT): Promise<void>;
|
|
42
|
+
_lock: string | null;
|
|
43
|
+
_decorateMethod<R, A extends unknown[]>(methodName: string, f: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
|
|
44
|
+
/**
|
|
45
|
+
* This returns an observable that will emit versions in real time.
|
|
46
|
+
* The current version is emitted once at first and then any update will be emitted.
|
|
47
|
+
* It is your responsability to then hook this to pull() when you want to refresh the data and make sure you do it in sequence, once at a time (you must prevent race conditions)
|
|
48
|
+
*/
|
|
49
|
+
listenNotifications(jwt: JWT): Observable<number>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/cloudsync/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAc,MAAM,kBAAkB,CAAC;AACxD,OAAY,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAGjC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,MAAM,MAAM,WAAW,GACnB;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,IAAI,EAAE,cAAc,CAAC;CACtB,CAAC;AAEN,qBAAa,YAAY;IACvB,aAAa,EAAE,aAAa,CAAC;IAC7B,iBAAiB,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IAC5C,aAAa,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;gBAE/C,EACV,aAAa,EACb,iBAAiB,EACjB,aAAa,GACd,EAAE;QACD,aAAa,EAAE,aAAa,CAAC;QAC7B;;WAEG;QACH,iBAAiB,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;QAC5C;;;WAGG;QACH,aAAa,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KACtD;IAUD;;;OAGG;IACG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B3E;;;OAGG;IACG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCrD,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE5B,eAAe,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EACpC,UAAU,EAAE,MAAM,EAClB,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC5B,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;IAiB7B;;;;OAIG;IACH,mBAAmB,CAAC,GAAG,EAAE,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC;CAGlD"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CloudSyncSDK = void 0;
|
|
16
|
+
const live_1 = require("./datatypes/live");
|
|
17
|
+
const api_1 = __importDefault(require("./api"));
|
|
18
|
+
const base64_js_1 = __importDefault(require("base64-js"));
|
|
19
|
+
const fflate_1 = require("fflate");
|
|
20
|
+
class CloudSyncSDK {
|
|
21
|
+
constructor({ trustchainSdk, getCurrentVersion, saveNewUpdate, }) {
|
|
22
|
+
this._lock = null;
|
|
23
|
+
this.trustchainSdk = trustchainSdk;
|
|
24
|
+
this.getCurrentVersion = getCurrentVersion;
|
|
25
|
+
this.saveNewUpdate = saveNewUpdate;
|
|
26
|
+
this.push = this._decorateMethod("push", this.push);
|
|
27
|
+
this.pull = this._decorateMethod("pull", this.pull);
|
|
28
|
+
this.destroy = this._decorateMethod("destroy", this.destroy);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Push new data to the Cloud Sync backend.
|
|
32
|
+
* Will fails if the version is out of sync. (conflicts)
|
|
33
|
+
*/
|
|
34
|
+
push(jwt, trustchain, data) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const validated = live_1.liveSchema.parse(data);
|
|
37
|
+
const json = JSON.stringify(validated);
|
|
38
|
+
const bytes = new TextEncoder().encode(json);
|
|
39
|
+
const compressed = yield new Promise((resolve, reject) => (0, fflate_1.compress)(bytes, (err, result) => (err ? reject(err) : resolve(result))));
|
|
40
|
+
const encrypted = yield this.trustchainSdk.encryptUserData(trustchain, compressed);
|
|
41
|
+
const base64 = base64_js_1.default.fromByteArray(encrypted);
|
|
42
|
+
const version = (this.getCurrentVersion() || 0) + 1;
|
|
43
|
+
const response = yield api_1.default.uploadData(jwt, "live", version, base64);
|
|
44
|
+
switch (response.status) {
|
|
45
|
+
case "updated": {
|
|
46
|
+
yield this.saveNewUpdate({
|
|
47
|
+
type: "pushed-data",
|
|
48
|
+
version,
|
|
49
|
+
});
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "out-of-sync": {
|
|
53
|
+
// WHAT TO DO? maybe we ignore because in this case we just wait for a pull?
|
|
54
|
+
console.warn("out-of-sync", response);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Pull new data from the Cloud Sync backend, if any.
|
|
61
|
+
* If new data is retrieved, it will be decrypted and saveNewUpdate will be called as part of this atomic process.
|
|
62
|
+
*/
|
|
63
|
+
pull(jwt, trustchain) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const response = yield api_1.default.fetchData(jwt, "live", this.getCurrentVersion());
|
|
66
|
+
switch (response.status) {
|
|
67
|
+
case "no-data": {
|
|
68
|
+
// no data, nothing to do
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case "up-to-date": {
|
|
72
|
+
// already up to date
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case "out-of-sync": {
|
|
76
|
+
const decrypted = yield this.trustchainSdk
|
|
77
|
+
.decryptUserData(trustchain, base64_js_1.default.toByteArray(response.payload))
|
|
78
|
+
.catch(e => {
|
|
79
|
+
// TODO if we fail to decrypt, it may mean we need to restore trustchain. and if it still fails and on specific error, we will have to eject. figure out how to integrate this in the pull lifecycle.
|
|
80
|
+
// or do we "let it fail" and handle it more globally on app side? TBD
|
|
81
|
+
throw e;
|
|
82
|
+
});
|
|
83
|
+
const decompressed = yield new Promise((resolve, reject) => (0, fflate_1.decompress)(decrypted, (err, result) => (err ? reject(err) : resolve(result))));
|
|
84
|
+
const json = JSON.parse(new TextDecoder().decode(decompressed));
|
|
85
|
+
const validated = live_1.liveSchema.parse(json);
|
|
86
|
+
const version = response.version;
|
|
87
|
+
yield this.saveNewUpdate({
|
|
88
|
+
type: "new-data",
|
|
89
|
+
data: validated,
|
|
90
|
+
version,
|
|
91
|
+
});
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
destroy(jwt) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
yield api_1.default.deleteData(jwt, "live");
|
|
100
|
+
yield this.saveNewUpdate({
|
|
101
|
+
type: "deleted-data",
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// this helpers will guarantee only one poll()/push() is performed at a time.
|
|
106
|
+
_decorateMethod(methodName, f) {
|
|
107
|
+
return (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const { _lock } = this;
|
|
109
|
+
if (_lock) {
|
|
110
|
+
return Promise.reject(new Error("CloudSyncSDK locked (" + this._lock + ")"));
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
this._lock = methodName;
|
|
114
|
+
return yield f.apply(this, args);
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
this._lock = null;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* This returns an observable that will emit versions in real time.
|
|
123
|
+
* The current version is emitted once at first and then any update will be emitted.
|
|
124
|
+
* It is your responsability to then hook this to pull() when you want to refresh the data and make sure you do it in sequence, once at a time (you must prevent race conditions)
|
|
125
|
+
*/
|
|
126
|
+
listenNotifications(jwt) {
|
|
127
|
+
return api_1.default.listenNotifications(jwt, "accounts");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.CloudSyncSDK = CloudSyncSDK;
|
|
131
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/cloudsync/sdk.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2CAAwD;AACxD,gDAAiC;AACjC,0DAA+B;AAC/B,mCAA8C;AAiB9C,MAAa,YAAY;IAKvB,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,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UAAW,WAAW,WAAW,WAAW,KAAG,MACpB,CAAC;AAEvE,eAAO,MAAM,wBAAwB,UAC5B,WAAW;eACU,MAAM;MACjC,OAAiD,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,UACjC,WAAW;aACM,OAAO;MAC9B,eAaF,CAAC;AAEF,eAAO,MAAM,2BAA2B,QAAS,UAAU,KAAG,eAkB7D,CAAC"}
|
package/lib/store.js
CHANGED
|
@@ -25,11 +25,19 @@ exports.handlers = {
|
|
|
25
25
|
starredAccountIds.add(starredId);
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
return {
|
|
28
|
+
return {
|
|
29
|
+
accountNames,
|
|
30
|
+
starredAccountIds,
|
|
31
|
+
};
|
|
29
32
|
},
|
|
30
33
|
SET_ACCOUNT_NAME: (state, { payload: { accountId, name } }) => {
|
|
31
34
|
const accountNames = new Map(state.accountNames);
|
|
32
|
-
|
|
35
|
+
if (!name) {
|
|
36
|
+
accountNames.delete(accountId);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
accountNames.set(accountId, name);
|
|
40
|
+
}
|
|
33
41
|
return Object.assign(Object.assign({}, state), { accountNames });
|
|
34
42
|
},
|
|
35
43
|
BULK_SET_ACCOUNT_NAMES: (state, { payload: { accountNames } }) => {
|