@lfdecentralizedtrust/paladin-sdk 0.13.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +21 -0
  2. package/build/domains/abis/INoto.json +448 -0
  3. package/build/domains/abis/INotoPrivate.json +347 -0
  4. package/build/domains/abis/IZetoFungible.json +197 -0
  5. package/build/domains/abis/PentePrivacyGroup.json +613 -0
  6. package/build/domains/abis/Zeto_Anon.json +1263 -0
  7. package/build/domains/noto.d.ts +117 -0
  8. package/build/domains/noto.js +292 -0
  9. package/build/domains/pente.d.ts +84 -0
  10. package/build/domains/pente.js +191 -0
  11. package/build/domains/zeto.d.ts +83 -0
  12. package/build/domains/zeto.js +201 -0
  13. package/build/index.d.ts +9 -0
  14. package/build/index.js +28 -0
  15. package/build/interfaces/algorithms.d.ts +3 -0
  16. package/build/interfaces/algorithms.js +9 -0
  17. package/build/interfaces/blockchainevent.d.ts +15 -0
  18. package/build/interfaces/blockchainevent.js +2 -0
  19. package/build/interfaces/blockindex.d.ts +30 -0
  20. package/build/interfaces/blockindex.js +2 -0
  21. package/build/interfaces/domains.d.ts +9 -0
  22. package/build/interfaces/domains.js +2 -0
  23. package/build/interfaces/index.d.ts +15 -0
  24. package/build/interfaces/index.js +31 -0
  25. package/build/interfaces/keymanager.d.ts +32 -0
  26. package/build/interfaces/keymanager.js +2 -0
  27. package/build/interfaces/logger.d.ts +8 -0
  28. package/build/interfaces/logger.js +2 -0
  29. package/build/interfaces/paladin.d.ts +14 -0
  30. package/build/interfaces/paladin.js +2 -0
  31. package/build/interfaces/privacygroups.d.ts +76 -0
  32. package/build/interfaces/privacygroups.js +2 -0
  33. package/build/interfaces/query.d.ts +33 -0
  34. package/build/interfaces/query.js +2 -0
  35. package/build/interfaces/registry.d.ts +26 -0
  36. package/build/interfaces/registry.js +2 -0
  37. package/build/interfaces/states.d.ts +61 -0
  38. package/build/interfaces/states.js +2 -0
  39. package/build/interfaces/transaction.d.ts +159 -0
  40. package/build/interfaces/transaction.js +12 -0
  41. package/build/interfaces/transport.d.ts +32 -0
  42. package/build/interfaces/transport.js +2 -0
  43. package/build/interfaces/verifiers.d.ts +6 -0
  44. package/build/interfaces/verifiers.js +10 -0
  45. package/build/interfaces/websocket.d.ts +57 -0
  46. package/build/interfaces/websocket.js +2 -0
  47. package/build/paladin.d.ts +265 -0
  48. package/build/paladin.js +739 -0
  49. package/build/transaction.d.ts +8 -0
  50. package/build/transaction.js +17 -0
  51. package/build/utils.d.ts +5 -0
  52. package/build/utils.js +49 -0
  53. package/build/verifier.d.ts +16 -0
  54. package/build/verifier.js +24 -0
  55. package/build/websocket.d.ts +35 -0
  56. package/build/websocket.js +177 -0
  57. package/build.gradle +75 -0
  58. package/package.json +32 -0
  59. package/scripts/abi.mjs +19 -0
  60. package/scripts/contracts.mjs +20 -0
  61. package/scripts/download.mjs +27 -0
  62. package/scripts/util.mjs +42 -0
  63. package/src/domains/noto.ts +420 -0
  64. package/src/domains/pente.ts +287 -0
  65. package/src/domains/zeto.ts +282 -0
  66. package/src/index.ts +10 -0
  67. package/src/interfaces/algorithms.ts +6 -0
  68. package/src/interfaces/blockchainevent.ts +18 -0
  69. package/src/interfaces/blockindex.ts +33 -0
  70. package/src/interfaces/domains.ts +10 -0
  71. package/src/interfaces/index.ts +15 -0
  72. package/src/interfaces/keymanager.ts +35 -0
  73. package/src/interfaces/logger.ts +8 -0
  74. package/src/interfaces/paladin.ts +17 -0
  75. package/src/interfaces/privacygroups.ts +86 -0
  76. package/src/interfaces/query.ts +37 -0
  77. package/src/interfaces/registry.ts +27 -0
  78. package/src/interfaces/states.ts +77 -0
  79. package/src/interfaces/transaction.ts +179 -0
  80. package/src/interfaces/transport.ts +35 -0
  81. package/src/interfaces/verifiers.ts +6 -0
  82. package/src/interfaces/websocket.ts +67 -0
  83. package/src/paladin.ts +1295 -0
  84. package/src/transaction.ts +17 -0
  85. package/src/utils.ts +24 -0
  86. package/src/verifier.ts +27 -0
  87. package/src/websocket.ts +217 -0
  88. package/tsconfig.json +14 -0
@@ -0,0 +1,8 @@
1
+ import PaladinClient from "./paladin";
2
+ export declare class TransactionFuture {
3
+ protected paladin: PaladinClient;
4
+ readonly id: string | Promise<string>;
5
+ constructor(paladin: PaladinClient, id: string | Promise<string>);
6
+ toString(): string | Promise<string>;
7
+ waitForReceipt(waitMs?: number, full?: boolean): Promise<import("./interfaces").ITransactionReceipt | undefined>;
8
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionFuture = void 0;
4
+ // Represents an in-flight transaction
5
+ class TransactionFuture {
6
+ constructor(paladin, id) {
7
+ this.paladin = paladin;
8
+ this.id = id;
9
+ }
10
+ toString() {
11
+ return this.id;
12
+ }
13
+ async waitForReceipt(waitMs = 5000, full = false) {
14
+ return this.paladin.pollForReceipt(await this.id, waitMs, full);
15
+ }
16
+ }
17
+ exports.TransactionFuture = TransactionFuture;
@@ -0,0 +1,5 @@
1
+ import { IStateBase, IStateEncoded } from "./interfaces";
2
+ export declare function encodeHex(data: string): string;
3
+ export declare function decodeHex(data: string): string;
4
+ export declare function newTransactionId(): string;
5
+ export declare const encodeStates: (states: IStateBase[]) => IStateEncoded[];
package/build/utils.js ADDED
@@ -0,0 +1,49 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.encodeStates = void 0;
27
+ exports.encodeHex = encodeHex;
28
+ exports.decodeHex = decodeHex;
29
+ exports.newTransactionId = newTransactionId;
30
+ const uuid = __importStar(require("uuid"));
31
+ function encodeHex(data) {
32
+ return "0x" + Buffer.from(data, "utf8").toString("hex");
33
+ }
34
+ function decodeHex(data) {
35
+ return Buffer.from(data.slice(2), "hex").toString("utf8");
36
+ }
37
+ function newTransactionId() {
38
+ return encodeHex(uuid.v4()) + "00000000000000000000000000000000";
39
+ }
40
+ const encodeStates = (states) => {
41
+ return states.map((state) => ({
42
+ id: state.id,
43
+ domain: state.domain,
44
+ schema: state.schema,
45
+ contractAddress: state.contractAddress,
46
+ data: encodeHex(JSON.stringify(state.data)),
47
+ }));
48
+ };
49
+ exports.encodeStates = encodeStates;
@@ -0,0 +1,16 @@
1
+ import { Algorithms, Verifiers } from "./interfaces";
2
+ import PaladinClient from "./paladin";
3
+ export declare class PaladinVerifier {
4
+ private paladin;
5
+ readonly lookup: string;
6
+ constructor(paladin: PaladinClient, lookup: string);
7
+ toString(): string;
8
+ split(): {
9
+ 0: string;
10
+ 1: string;
11
+ identity: string;
12
+ node: string;
13
+ };
14
+ resolve(algorithm: Algorithms, verifierType: Verifiers): Promise<string>;
15
+ address(): Promise<string>;
16
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaladinVerifier = void 0;
4
+ const interfaces_1 = require("./interfaces");
5
+ class PaladinVerifier {
6
+ constructor(paladin, lookup) {
7
+ this.paladin = paladin;
8
+ this.lookup = lookup;
9
+ }
10
+ toString() {
11
+ return this.lookup;
12
+ }
13
+ split() {
14
+ const [identity, node] = this.lookup.split("@");
15
+ return { 0: identity, 1: node, identity, node };
16
+ }
17
+ resolve(algorithm, verifierType) {
18
+ return this.paladin.ptx.resolveVerifier(this.lookup, algorithm, verifierType);
19
+ }
20
+ address() {
21
+ return this.resolve(interfaces_1.Algorithms.ECDSA_SECP256K1, interfaces_1.Verifiers.ETH_ADDRESS);
22
+ }
23
+ }
24
+ exports.PaladinVerifier = PaladinVerifier;
@@ -0,0 +1,35 @@
1
+ import { PrivacyGroupWebSocketEvent, WebSocketClientOptions, WebSocketEvent, WebSocketEventCallback } from "./interfaces/websocket";
2
+ declare abstract class PaladinWebSocketClientBase<TMessageTypes extends string, TEvent> {
3
+ private options;
4
+ private callback;
5
+ private logger;
6
+ private socket;
7
+ private closed?;
8
+ private pingTimer?;
9
+ private disconnectTimer?;
10
+ private reconnectTimer?;
11
+ private disconnectDetected;
12
+ private counter;
13
+ constructor(options: WebSocketClientOptions<TMessageTypes>, callback: WebSocketEventCallback<TEvent>);
14
+ private connect;
15
+ private clearPingTimers;
16
+ private schedulePing;
17
+ private reconnect;
18
+ send(json: object): void;
19
+ sendRpc(method: string, params: any[]): void;
20
+ close(wait?: boolean): Promise<void>;
21
+ abstract subscribe(type: TMessageTypes, name: string): void;
22
+ abstract ack(subscription: string): void;
23
+ abstract nack(subscription: string): void;
24
+ }
25
+ export declare class PaladinWebSocketClient extends PaladinWebSocketClientBase<"receipts" | "blockchainevents", WebSocketEvent> {
26
+ subscribe(type: "receipts" | "blockchainevents", name: string): void;
27
+ ack(subscription: string): void;
28
+ nack(subscription: string): void;
29
+ }
30
+ export declare class PrivacyGroupWebSocketClient extends PaladinWebSocketClientBase<"messages", PrivacyGroupWebSocketEvent> {
31
+ subscribe(type: "messages", name: string): void;
32
+ ack(subscription: string): void;
33
+ nack(subscription: string): void;
34
+ }
35
+ export {};
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PrivacyGroupWebSocketClient = exports.PaladinWebSocketClient = void 0;
7
+ const stream_1 = require("stream");
8
+ const ws_1 = __importDefault(require("ws"));
9
+ class PaladinWebSocketClientBase {
10
+ constructor(options, callback) {
11
+ this.options = options;
12
+ this.callback = callback;
13
+ this.closed = () => { };
14
+ this.disconnectDetected = false;
15
+ this.counter = 1;
16
+ this.logger = options.logger ?? console;
17
+ this.connect();
18
+ }
19
+ connect() {
20
+ // Ensure we've cleaned up any old socket
21
+ this.close();
22
+ if (this.reconnectTimer) {
23
+ clearTimeout(this.reconnectTimer);
24
+ delete this.reconnectTimer;
25
+ }
26
+ const auth = this.options.username && this.options.password
27
+ ? `${this.options.username}:${this.options.password}`
28
+ : undefined;
29
+ const socket = (this.socket = new ws_1.default(this.options.url, {
30
+ ...this.options.socketOptions,
31
+ auth,
32
+ handshakeTimeout: this.options.heartbeatInterval,
33
+ }));
34
+ this.closed = undefined;
35
+ socket
36
+ .on("open", () => {
37
+ if (this.disconnectDetected) {
38
+ this.disconnectDetected = false;
39
+ this.logger.log("Connection restored");
40
+ }
41
+ else {
42
+ this.logger.log("Connected");
43
+ }
44
+ this.schedulePing();
45
+ for (const sub of this.options.subscriptions ?? []) {
46
+ // Automatically connect subscriptions
47
+ this.subscribe(sub.type, sub.name);
48
+ this.logger.log(`Started listening on subscription ${sub.name}`);
49
+ }
50
+ if (this.options?.afterConnect !== undefined) {
51
+ this.options.afterConnect(this);
52
+ }
53
+ })
54
+ .on("error", (err) => {
55
+ this.logger.error("Error", err.stack);
56
+ })
57
+ .on("close", () => {
58
+ if (this.closed) {
59
+ this.logger.log("Closed");
60
+ this.closed(); // do this after all logging
61
+ }
62
+ else {
63
+ this.disconnectDetected = true;
64
+ this.reconnect("Closed by peer");
65
+ }
66
+ })
67
+ .on("pong", () => {
68
+ this.logger.debug && this.logger.debug(`WS received pong`);
69
+ this.schedulePing();
70
+ })
71
+ .on("unexpected-response", (req, res) => {
72
+ let responseData = "";
73
+ res.pipe(new stream_1.Transform({
74
+ transform(chunk, encoding, callback) {
75
+ responseData += chunk;
76
+ callback();
77
+ },
78
+ flush: () => {
79
+ this.reconnect(`Websocket connect error [${res.statusCode}]: ${responseData}`);
80
+ },
81
+ }));
82
+ })
83
+ .on("message", (data) => {
84
+ const event = JSON.parse(data.toString());
85
+ this.callback(this, event);
86
+ });
87
+ }
88
+ clearPingTimers() {
89
+ if (this.disconnectTimer) {
90
+ clearTimeout(this.disconnectTimer);
91
+ delete this.disconnectTimer;
92
+ }
93
+ if (this.pingTimer) {
94
+ clearTimeout(this.pingTimer);
95
+ delete this.pingTimer;
96
+ }
97
+ }
98
+ schedulePing() {
99
+ this.clearPingTimers();
100
+ const heartbeatInterval = this.options.heartbeatInterval ?? 30000;
101
+ this.disconnectTimer = setTimeout(() => this.reconnect("Heartbeat timeout"), Math.ceil(heartbeatInterval * 1.5) // 50% grace period
102
+ );
103
+ this.pingTimer = setTimeout(() => {
104
+ this.logger.debug && this.logger.debug(`WS sending ping`);
105
+ this.socket?.ping("ping", true, (err) => {
106
+ if (err)
107
+ this.reconnect(err.message);
108
+ });
109
+ }, heartbeatInterval);
110
+ }
111
+ reconnect(msg) {
112
+ if (!this.reconnectTimer) {
113
+ this.close();
114
+ this.logger.error(`Websocket closed: ${msg}`);
115
+ if (this.options.reconnectDelay === -1) {
116
+ // do not attempt to reconnect
117
+ }
118
+ else {
119
+ this.reconnectTimer = setTimeout(() => this.connect(), this.options.reconnectDelay ?? 5000);
120
+ }
121
+ }
122
+ }
123
+ send(json) {
124
+ if (this.socket !== undefined) {
125
+ this.socket.send(JSON.stringify(json));
126
+ }
127
+ }
128
+ sendRpc(method, params) {
129
+ this.send({
130
+ jsonrpc: "2.0",
131
+ id: this.counter++,
132
+ method,
133
+ params,
134
+ });
135
+ }
136
+ async close(wait) {
137
+ const closedPromise = new Promise((resolve) => {
138
+ this.closed = resolve;
139
+ });
140
+ this.clearPingTimers();
141
+ if (this.socket) {
142
+ try {
143
+ this.socket.close();
144
+ }
145
+ catch (e) {
146
+ this.logger.warn(`Failed to clean up websocket: ${e.message}`);
147
+ }
148
+ if (wait)
149
+ await closedPromise;
150
+ this.socket = undefined;
151
+ }
152
+ }
153
+ }
154
+ class PaladinWebSocketClient extends PaladinWebSocketClientBase {
155
+ subscribe(type, name) {
156
+ this.sendRpc("ptx_subscribe", [type, name]);
157
+ }
158
+ ack(subscription) {
159
+ this.sendRpc("ptx_ack", [subscription]);
160
+ }
161
+ nack(subscription) {
162
+ this.sendRpc("ptx_nack", [subscription]);
163
+ }
164
+ }
165
+ exports.PaladinWebSocketClient = PaladinWebSocketClient;
166
+ class PrivacyGroupWebSocketClient extends PaladinWebSocketClientBase {
167
+ subscribe(type, name) {
168
+ this.sendRpc("pgroup_subscribe", [type, name]);
169
+ }
170
+ ack(subscription) {
171
+ this.sendRpc("pgroup_ack", [subscription]);
172
+ }
173
+ nack(subscription) {
174
+ this.sendRpc("pgroup_nack", [subscription]);
175
+ }
176
+ }
177
+ exports.PrivacyGroupWebSocketClient = PrivacyGroupWebSocketClient;
package/build.gradle ADDED
@@ -0,0 +1,75 @@
1
+ /*
2
+ * Copyright © 2024 Kaleido, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5
+ * the License. You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11
+ * specific language governing permissions and limitations under the License.
12
+ *
13
+ * SPDX-License-Identifier: Apache-2.0
14
+ */
15
+
16
+ configurations {
17
+ // Resolvable configurations
18
+ contractCompile {
19
+ canBeConsumed = false
20
+ canBeResolved = true
21
+ }
22
+ zetoArtifacts {
23
+ canBeConsumed = false
24
+ canBeResolved = true
25
+ }
26
+
27
+ // Consumable configurations
28
+ buildSDK {
29
+ canBeConsumed = true
30
+ canBeResolved = false
31
+ }
32
+ }
33
+
34
+ dependencies {
35
+ contractCompile project(path: ":solidity", configuration: "compiledContracts")
36
+ zetoArtifacts project(path: ":domains:zeto", configuration: "zetoArtifacts")
37
+ }
38
+
39
+ task install(type: Exec) {
40
+ executable 'npm'
41
+ args 'install'
42
+
43
+ inputs.files("package.json")
44
+ outputs.files("package-lock.json")
45
+ outputs.dir("node_modules")
46
+ }
47
+
48
+ task copyABI(type: Exec, dependsOn: install) {
49
+ executable 'npm'
50
+ args 'run'
51
+ args 'abi'
52
+
53
+ inputs.files(configurations.contractCompile)
54
+ inputs.files(configurations.zetoArtifacts)
55
+ outputs.dir('src/domains/abis')
56
+ }
57
+
58
+ task build(type: Exec, dependsOn: [install, copyABI]) {
59
+ executable 'npm'
60
+ args 'run'
61
+ args 'build'
62
+
63
+ inputs.dir("src")
64
+ outputs.dir("build")
65
+ }
66
+
67
+ task clean(type: Delete) {
68
+ delete "node_modules"
69
+ delete "build"
70
+ delete "src/domains/abis"
71
+ }
72
+
73
+ dependencies {
74
+ buildSDK files(build)
75
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@lfdecentralizedtrust/paladin-sdk",
3
+ "version": "0.13.0-rc.1",
4
+ "description": "",
5
+ "main": "build/index.js",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "abi": "node scripts/abi.mjs",
9
+ "download-abi": "node scripts/contracts.mjs"
10
+ },
11
+ "author": "",
12
+ "license": "Apache-2.0",
13
+ "devDependencies": {
14
+ "@types/node": "^22.9.0",
15
+ "@types/ws": "^8.18.0",
16
+ "copy-file": "^11.0.0",
17
+ "node-fetch": "^3.3.2",
18
+ "tar": "^7.4.3",
19
+ "typescript": "^5.6.3"
20
+ },
21
+ "dependencies": {
22
+ "ethers": "^6.13.4",
23
+ "uuid": "^11.0.2",
24
+ "ws": "^8.18.1"
25
+ },
26
+ "peerDependencies": {
27
+ "axios": "^1.7.7"
28
+ },
29
+ "repository": {
30
+ "url": "https://github.com/LFDT-Paladin/paladin"
31
+ }
32
+ }
@@ -0,0 +1,19 @@
1
+ import { copyFile } from 'copy-file';
2
+ import path from 'path';
3
+ import { downloadZetoAbis } from './download.mjs';
4
+
5
+ await copyFile('../../solidity/artifacts/contracts/domains/pente/PentePrivacyGroup.sol/PentePrivacyGroup.json', 'src/domains/abis/PentePrivacyGroup.json');
6
+
7
+ await copyFile('../../solidity/artifacts/contracts/domains/interfaces/INoto.sol/INoto.json', 'src/domains/abis/INoto.json');
8
+
9
+ await copyFile('../../solidity/artifacts/contracts/domains/interfaces/INotoPrivate.sol/INotoPrivate.json', 'src/domains/abis/INotoPrivate.json');
10
+
11
+ await copyFile('../../solidity/artifacts/contracts/domains/interfaces/IZetoFungible.sol/IZetoFungible.json', 'src/domains/abis/IZetoFungible.json');
12
+
13
+ // download the zeto anon contract ABI
14
+ const tmpDir = await downloadZetoAbis();
15
+
16
+ // copy the zeto anon contract ABI
17
+ await copyFile(path.join(tmpDir, 'artifacts/contracts/zeto_anon.sol/Zeto_Anon.json'), 'src/domains/abis/Zeto_Anon.json');
18
+ await copyFile(path.join(tmpDir, 'artifacts/contracts/lib/interfaces/izeto_kyc.sol/IZetoKyc.json'), 'src/domains/abis/IZetoKyc.json');
19
+ await copyFile(path.join(tmpDir, 'artifacts/contracts/erc20.sol/SampleERC20.json'), 'src/domains/abis/SampleERC20.json');
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+
3
+ import path from 'path';
4
+ import { copyFile } from 'copy-file';
5
+ import { downloadZetoAbis, downloadPaladinAbis } from './download.mjs';
6
+
7
+ // download zeto and paladin abis and copy them to the contracts directory
8
+ const zetoDir = await downloadZetoAbis();
9
+ const paladinDir = await downloadPaladinAbis();
10
+
11
+ // copy the zeto abis
12
+ await copyFile(path.join(zetoDir, 'artifacts/contracts/zeto_anon.sol/Zeto_Anon.json'), 'src/domains/abis/Zeto_Anon.json');
13
+ await copyFile(path.join(zetoDir, 'artifacts/contracts/lib/interfaces/izeto_kyc.sol/IZetoKyc.json'), 'src/domains/abis/IZetoKyc.json');
14
+ await copyFile(path.join(zetoDir, 'artifacts/contracts/erc20.sol/SampleERC20.json'), 'src/domains/abis/SampleERC20.json');
15
+
16
+ // copy the paladin abis
17
+ await copyFile(path.join(paladinDir, 'abis/PentePrivacyGroup.json'), 'src/domains/abis/PentePrivacyGroup.json');
18
+ await copyFile(path.join(paladinDir, 'abis/INoto.json'), 'src/domains/abis/INoto.json');
19
+ await copyFile(path.join(paladinDir, 'abis/INotoPrivate.json'), 'src/domains/abis/INotoPrivate.json');
20
+ await copyFile(path.join(paladinDir, 'abis/IZetoFungible.json'), 'src/domains/abis/IZetoFungible.json');
@@ -0,0 +1,27 @@
1
+ // download the zeto contracts
2
+ import { downloadFile, extractFile } from './util.mjs';
3
+
4
+ export async function downloadZetoAbis(zetoVersion = 'v0.2.0') {
5
+
6
+ const zetoOrg = 'hyperledger-labs';
7
+ const filename = `zeto-contracts-${zetoVersion}.tar.gz`;
8
+ const url = `https://github.com/${zetoOrg}/zeto/releases/download/${zetoVersion}/${filename}`;
9
+ const tmpFilePath = await downloadFile(url, filename);
10
+ const tmpDir = await extractFile(tmpFilePath);
11
+ return tmpDir;
12
+ }
13
+
14
+ // download the paladin contracts
15
+ export async function downloadPaladinAbis(paladinVersion = 'latest') {
16
+ const paladinOrg = 'LFDT-Paladin';
17
+ const filename = `abis.tar.gz`;
18
+ let url;
19
+ if (paladinVersion === "latest") {
20
+ url = `https://github.com/${paladinOrg}/paladin/releases/latest/download/${filename}`;
21
+ } else {
22
+ url = `https://github.com/${paladinOrg}/paladin/releases/download/${paladinVersion}/${filename}`;
23
+ }
24
+ const tmpFilePath = await downloadFile(url, filename);
25
+ const tmpDir = await extractFile(tmpFilePath, 'abis');
26
+ return tmpDir;
27
+ }
@@ -0,0 +1,42 @@
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+ import fetch from 'node-fetch';
5
+ import * as tar from 'tar';
6
+
7
+ export async function downloadFile(url, filename) {
8
+ try {
9
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'paladin-sdk'));
10
+ const tmpFilePath = path.join(tmpDir, filename);
11
+ const response = await fetch(url);
12
+ if (!response.ok) {
13
+ throw new Error(`HTTP error! status: ${response.status}`);
14
+ }
15
+ const fileStream = fs.createWriteStream(tmpFilePath);
16
+ await new Promise((resolve, reject) => {
17
+ response.body.pipe(fileStream);
18
+ response.body.on('error', reject);
19
+ fileStream.on('finish', resolve);
20
+ });
21
+ console.log(`File downloaded successfully to: ${tmpFilePath}`);
22
+ return tmpFilePath;
23
+ } catch (error) {
24
+ console.error('Error downloading file:', error);
25
+ }
26
+ }
27
+
28
+ export async function extractFile(filePath, destinationDir) {
29
+ try {
30
+ let tmpDir = path.dirname(filePath);
31
+ let fullPath = tmpDir;
32
+ if (destinationDir) {
33
+ fullPath = path.join(tmpDir, destinationDir);
34
+ fs.mkdirSync(fullPath, { recursive: true });
35
+ }
36
+ await tar.x({ file: filePath, C: fullPath });
37
+ console.log(`File extracted successfully to: ${fullPath}`);
38
+ return tmpDir;
39
+ } catch (error) {
40
+ console.error('Error extracting file:', error);
41
+ }
42
+ }