@getpara/rest-sdk 2.32.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.
- package/README.md +175 -0
- package/dist/cjs/ethers/index.js +193 -0
- package/dist/cjs/index.js +339 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/solana/index.js +246 -0
- package/dist/cjs/viem/index.js +178 -0
- package/dist/esm/ethers/index.js +168 -0
- package/dist/esm/index.js +312 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/solana/index.js +225 -0
- package/dist/esm/viem/index.js +157 -0
- package/dist/types/ethers/index.d.ts +23 -0
- package/dist/types/index.d.ts +292 -0
- package/dist/types/solana/index.d.ts +12 -0
- package/dist/types/viem/index.d.ts +11 -0
- package/package.json +114 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var src_exports = {};
|
|
39
|
+
__export(src_exports, {
|
|
40
|
+
ParaRestClient: () => ParaRestClient,
|
|
41
|
+
ParaRestError: () => ParaRestError,
|
|
42
|
+
ParaRestSerializationError: () => ParaRestSerializationError,
|
|
43
|
+
ParaRestValidationError: () => ParaRestValidationError,
|
|
44
|
+
toRestJson: () => toRestJson
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(src_exports);
|
|
47
|
+
class ParaRestError extends Error {
|
|
48
|
+
constructor({
|
|
49
|
+
status,
|
|
50
|
+
code,
|
|
51
|
+
requestId,
|
|
52
|
+
body,
|
|
53
|
+
message
|
|
54
|
+
}) {
|
|
55
|
+
var _a;
|
|
56
|
+
super((_a = message != null ? message : code) != null ? _a : `Para REST request failed with status ${status}`);
|
|
57
|
+
this.name = "ParaRestError";
|
|
58
|
+
this.status = status;
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.requestId = requestId;
|
|
61
|
+
this.body = body;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
class ParaRestSerializationError extends Error {
|
|
65
|
+
constructor(message) {
|
|
66
|
+
super(message);
|
|
67
|
+
this.name = "ParaRestSerializationError";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
class ParaRestValidationError extends Error {
|
|
71
|
+
constructor(message) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.name = "ParaRestValidationError";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const BASE_URLS = {
|
|
77
|
+
PROD: "https://api.getpara.com",
|
|
78
|
+
BETA: "https://api.beta.getpara.com",
|
|
79
|
+
SANDBOX: "https://api.sandbox.getpara.com"
|
|
80
|
+
};
|
|
81
|
+
function toRestJson(body) {
|
|
82
|
+
let json;
|
|
83
|
+
try {
|
|
84
|
+
json = JSON.stringify(body, (_key, value) => {
|
|
85
|
+
if (typeof value === "bigint") return value.toString(10);
|
|
86
|
+
if (typeof value === "function") {
|
|
87
|
+
throw new ParaRestSerializationError("REST request body cannot contain functions");
|
|
88
|
+
}
|
|
89
|
+
if (typeof value === "symbol") {
|
|
90
|
+
throw new ParaRestSerializationError("REST request body cannot contain symbols");
|
|
91
|
+
}
|
|
92
|
+
return value;
|
|
93
|
+
});
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (err instanceof ParaRestSerializationError) throw err;
|
|
96
|
+
if (err instanceof TypeError) {
|
|
97
|
+
throw new ParaRestSerializationError("REST request body cannot contain circular references");
|
|
98
|
+
}
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
if (typeof json !== "string") {
|
|
102
|
+
throw new ParaRestSerializationError("REST request body must be JSON serializable");
|
|
103
|
+
}
|
|
104
|
+
return json;
|
|
105
|
+
}
|
|
106
|
+
class ParaRestClient {
|
|
107
|
+
constructor(options) {
|
|
108
|
+
var _a, _b, _c;
|
|
109
|
+
if (!options.apiKey) {
|
|
110
|
+
throw new ParaRestValidationError("apiKey is required");
|
|
111
|
+
}
|
|
112
|
+
this.apiKey = options.apiKey;
|
|
113
|
+
this.baseUrl = resolveBaseUrl((_a = options.env) != null ? _a : "PROD");
|
|
114
|
+
this.fetchImpl = (_b = options.fetch) != null ? _b : getGlobalFetch();
|
|
115
|
+
this.requestIdGenerator = (_c = options.requestIdGenerator) != null ? _c : defaultRequestId;
|
|
116
|
+
}
|
|
117
|
+
createWallet(body, options) {
|
|
118
|
+
requireBody(body, "body");
|
|
119
|
+
requireNonEmpty(body.type, "type");
|
|
120
|
+
requireNonEmpty(body.userIdentifier, "userIdentifier");
|
|
121
|
+
requireNonEmpty(body.userIdentifierType, "userIdentifierType");
|
|
122
|
+
return this.request("POST", "/v1/wallets", { body, options, expectedStatus: 201 });
|
|
123
|
+
}
|
|
124
|
+
listWallets(query, options) {
|
|
125
|
+
return this.request("GET", `/v1/wallets${queryString(query)}`, { options });
|
|
126
|
+
}
|
|
127
|
+
getWallet(walletId, options) {
|
|
128
|
+
return this.request("GET", `/v1/wallets/${walletPath(walletId)}`, { options });
|
|
129
|
+
}
|
|
130
|
+
updateWalletIdentifier(walletId, body, options) {
|
|
131
|
+
requireNonEmpty(walletId, "walletId");
|
|
132
|
+
requireBody(body, "body");
|
|
133
|
+
requireNonEmpty(body.userIdentifier, "userIdentifier");
|
|
134
|
+
requireNonEmpty(body.userIdentifierType, "userIdentifierType");
|
|
135
|
+
return this.request("PATCH", `/v1/wallets/${walletPath(walletId)}`, { body, options });
|
|
136
|
+
}
|
|
137
|
+
migrateShare(walletId, body, options) {
|
|
138
|
+
requireNonEmpty(walletId, "walletId");
|
|
139
|
+
requireBody(body, "body");
|
|
140
|
+
requireNonEmpty(body.encryptedPayload, "encryptedPayload");
|
|
141
|
+
return this.request("POST", `/v1/wallets/${walletPath(walletId)}/migrate-share`, { body, options });
|
|
142
|
+
}
|
|
143
|
+
getEnclavePublicKey(options) {
|
|
144
|
+
return this.request("GET", "/v1/enclave/public-key", { options });
|
|
145
|
+
}
|
|
146
|
+
getWalletBalance(walletId, query, options) {
|
|
147
|
+
return this.request("GET", `/v1/wallets/${walletPath(walletId)}/balance${queryString(query)}`, { options });
|
|
148
|
+
}
|
|
149
|
+
signRaw(walletId, body, options) {
|
|
150
|
+
requireNonEmpty(walletId, "walletId");
|
|
151
|
+
requireBody(body, "body");
|
|
152
|
+
requireNonEmpty(body.data, "data");
|
|
153
|
+
return this.request("POST", `/v1/wallets/${walletPath(walletId)}/sign-raw`, { body, options });
|
|
154
|
+
}
|
|
155
|
+
signMessage(walletId, body, options) {
|
|
156
|
+
requireNonEmpty(walletId, "walletId");
|
|
157
|
+
requireBody(body, "body");
|
|
158
|
+
requireNonEmpty(body.message, "message");
|
|
159
|
+
return this.request("POST", `/v1/wallets/${walletPath(walletId)}/sign-message`, { body, options });
|
|
160
|
+
}
|
|
161
|
+
signTransaction(walletId, body, options) {
|
|
162
|
+
requireNonEmpty(walletId, "walletId");
|
|
163
|
+
requireBody(body, "body");
|
|
164
|
+
if (body.transaction == null || body.transaction === "") {
|
|
165
|
+
throw new ParaRestValidationError("transaction is required");
|
|
166
|
+
}
|
|
167
|
+
return this.request("POST", `/v1/wallets/${walletPath(walletId)}/sign-transaction`, { body, options });
|
|
168
|
+
}
|
|
169
|
+
signTypedData(walletId, body, options) {
|
|
170
|
+
requireNonEmpty(walletId, "walletId");
|
|
171
|
+
requireBody(body, "body");
|
|
172
|
+
requireBody(body.typedData, "typedData");
|
|
173
|
+
requireBody(body.typedData.domain, "typedData.domain");
|
|
174
|
+
requireBody(body.typedData.types, "typedData.types");
|
|
175
|
+
requireNonEmpty(body.typedData.primaryType, "typedData.primaryType");
|
|
176
|
+
requireBody(body.typedData.message, "typedData.message");
|
|
177
|
+
return this.request("POST", `/v1/wallets/${walletPath(walletId)}/sign-typed-data`, { body, options });
|
|
178
|
+
}
|
|
179
|
+
signAuthorization(walletId, body, options) {
|
|
180
|
+
requireNonEmpty(walletId, "walletId");
|
|
181
|
+
requireBody(body, "body");
|
|
182
|
+
requireBody(body.authorization, "authorization");
|
|
183
|
+
if (!body.authorization.address && !body.authorization.contractAddress) {
|
|
184
|
+
throw new ParaRestValidationError("authorization.address is required");
|
|
185
|
+
}
|
|
186
|
+
if (body.authorization.chainId == null) {
|
|
187
|
+
throw new ParaRestValidationError("authorization.chainId is required");
|
|
188
|
+
}
|
|
189
|
+
if (body.authorization.nonce == null) {
|
|
190
|
+
throw new ParaRestValidationError("authorization.nonce is required");
|
|
191
|
+
}
|
|
192
|
+
return this.request("POST", `/v1/wallets/${walletPath(walletId)}/sign-authorization`, { body, options });
|
|
193
|
+
}
|
|
194
|
+
transfer(walletId, body, options) {
|
|
195
|
+
requireNonEmpty(walletId, "walletId");
|
|
196
|
+
requireBody(body, "body");
|
|
197
|
+
requireNonEmpty(body.to, "to");
|
|
198
|
+
requireNonEmpty(body.value, "value");
|
|
199
|
+
return this.request("POST", `/v1/wallets/${walletPath(walletId)}/transfer`, { body, options });
|
|
200
|
+
}
|
|
201
|
+
estimateFee(walletId, body, options) {
|
|
202
|
+
requireNonEmpty(walletId, "walletId");
|
|
203
|
+
requireBody(body, "body");
|
|
204
|
+
requireNonEmpty(body.to, "to");
|
|
205
|
+
requireNonEmpty(body.value, "value");
|
|
206
|
+
return this.request("POST", `/v1/wallets/${walletPath(walletId)}/estimate-fee`, { body, options });
|
|
207
|
+
}
|
|
208
|
+
requestFaucet(body, options) {
|
|
209
|
+
requireBody(body, "body");
|
|
210
|
+
requireNonEmpty(body.walletId, "walletId");
|
|
211
|
+
return this.request("POST", "/faucet", { body, options });
|
|
212
|
+
}
|
|
213
|
+
listRestTransactions(walletId, query, options) {
|
|
214
|
+
return this.request("GET", `/v1/wallets/${walletPath(walletId)}/transactions${queryString(query)}`, { options });
|
|
215
|
+
}
|
|
216
|
+
getRestTransaction(walletId, transactionId, options) {
|
|
217
|
+
return this.request(
|
|
218
|
+
"GET",
|
|
219
|
+
`/v1/wallets/${walletPath(walletId)}/transactions/${pathSegment("transactionId", transactionId)}`,
|
|
220
|
+
{
|
|
221
|
+
options
|
|
222
|
+
}
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
request(_0, _1) {
|
|
226
|
+
return __async(this, arguments, function* (method, path, {
|
|
227
|
+
body,
|
|
228
|
+
options,
|
|
229
|
+
expectedStatus
|
|
230
|
+
} = {}) {
|
|
231
|
+
var _a;
|
|
232
|
+
const requestId = this.requestIdGenerator();
|
|
233
|
+
const headers = {
|
|
234
|
+
"Accept": "application/json",
|
|
235
|
+
"X-API-Key": this.apiKey,
|
|
236
|
+
"X-Request-Id": requestId
|
|
237
|
+
};
|
|
238
|
+
let requestBody;
|
|
239
|
+
if (body !== void 0) {
|
|
240
|
+
requestBody = toRestJson(body);
|
|
241
|
+
headers["Content-Type"] = "application/json";
|
|
242
|
+
}
|
|
243
|
+
if (options == null ? void 0 : options.idempotencyKey) {
|
|
244
|
+
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
245
|
+
}
|
|
246
|
+
const response = yield this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
247
|
+
body: requestBody,
|
|
248
|
+
headers,
|
|
249
|
+
method,
|
|
250
|
+
signal: options == null ? void 0 : options.signal
|
|
251
|
+
});
|
|
252
|
+
const parsed = yield parseBody(response);
|
|
253
|
+
if (!response.ok || expectedStatus != null && response.status !== expectedStatus) {
|
|
254
|
+
const responseBody = isRecord(parsed) ? parsed : {};
|
|
255
|
+
throw new ParaRestError({
|
|
256
|
+
status: response.status,
|
|
257
|
+
code: stringField(responseBody.code),
|
|
258
|
+
requestId: (_a = response.headers.get("x-request-id")) != null ? _a : requestId,
|
|
259
|
+
body: parsed,
|
|
260
|
+
message: stringField(responseBody.message)
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
return parsed;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function resolveBaseUrl(env) {
|
|
268
|
+
const baseUrl = typeof env === "string" ? BASE_URLS[env] : env.baseUrl;
|
|
269
|
+
if (!baseUrl) {
|
|
270
|
+
throw new ParaRestValidationError("baseUrl is required");
|
|
271
|
+
}
|
|
272
|
+
return baseUrl.replace(/\/+$/, "");
|
|
273
|
+
}
|
|
274
|
+
function getGlobalFetch() {
|
|
275
|
+
const fetchImpl = globalThis.fetch;
|
|
276
|
+
if (!fetchImpl) {
|
|
277
|
+
throw new ParaRestValidationError("fetch is required in this runtime; pass options.fetch");
|
|
278
|
+
}
|
|
279
|
+
return fetchImpl;
|
|
280
|
+
}
|
|
281
|
+
function defaultRequestId() {
|
|
282
|
+
const crypto = globalThis.crypto;
|
|
283
|
+
if (crypto == null ? void 0 : crypto.randomUUID) {
|
|
284
|
+
return crypto.randomUUID();
|
|
285
|
+
}
|
|
286
|
+
return `req_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;
|
|
287
|
+
}
|
|
288
|
+
function walletPath(walletId) {
|
|
289
|
+
return pathSegment("walletId", walletId);
|
|
290
|
+
}
|
|
291
|
+
function pathSegment(name, value) {
|
|
292
|
+
requireNonEmpty(value, name);
|
|
293
|
+
return encodeURIComponent(value);
|
|
294
|
+
}
|
|
295
|
+
function requireBody(value, name) {
|
|
296
|
+
if (!isRecord(value)) {
|
|
297
|
+
throw new ParaRestValidationError(`${name} is required`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function requireNonEmpty(value, name) {
|
|
301
|
+
if (value == null || value === "") {
|
|
302
|
+
throw new ParaRestValidationError(`${name} is required`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function queryString(query) {
|
|
306
|
+
if (!query) return "";
|
|
307
|
+
const params = new URLSearchParams();
|
|
308
|
+
for (const [key, value] of Object.entries(query)) {
|
|
309
|
+
if (value == null) continue;
|
|
310
|
+
params.set(key, String(value));
|
|
311
|
+
}
|
|
312
|
+
const serialized = params.toString();
|
|
313
|
+
return serialized ? `?${serialized}` : "";
|
|
314
|
+
}
|
|
315
|
+
function parseBody(response) {
|
|
316
|
+
return __async(this, null, function* () {
|
|
317
|
+
const text = yield response.text();
|
|
318
|
+
if (!text) return void 0;
|
|
319
|
+
try {
|
|
320
|
+
return JSON.parse(text);
|
|
321
|
+
} catch (e) {
|
|
322
|
+
return text;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
function isRecord(value) {
|
|
327
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
328
|
+
}
|
|
329
|
+
function stringField(value) {
|
|
330
|
+
return typeof value === "string" ? value : void 0;
|
|
331
|
+
}
|
|
332
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
333
|
+
0 && (module.exports = {
|
|
334
|
+
ParaRestClient,
|
|
335
|
+
ParaRestError,
|
|
336
|
+
ParaRestSerializationError,
|
|
337
|
+
ParaRestValidationError,
|
|
338
|
+
toRestJson
|
|
339
|
+
});
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
var __async = (__this, __arguments, generator) => {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
var fulfilled = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.next(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var rejected = (value) => {
|
|
45
|
+
try {
|
|
46
|
+
step(generator.throw(value));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
reject(e);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
52
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
var solana_exports = {};
|
|
56
|
+
__export(solana_exports, {
|
|
57
|
+
createParaRestSolanaSigner: () => createParaRestSolanaSigner
|
|
58
|
+
});
|
|
59
|
+
module.exports = __toCommonJS(solana_exports);
|
|
60
|
+
var import__ = require("../index.js");
|
|
61
|
+
function createParaRestSolanaSigner(options) {
|
|
62
|
+
if (!options.client) {
|
|
63
|
+
throw new import__.ParaRestValidationError("ParaRestSolanaSigner: client is required");
|
|
64
|
+
}
|
|
65
|
+
if (!options.walletId) {
|
|
66
|
+
throw new import__.ParaRestValidationError("ParaRestSolanaSigner: walletId is required");
|
|
67
|
+
}
|
|
68
|
+
if (!options.address) {
|
|
69
|
+
throw new import__.ParaRestValidationError("ParaRestSolanaSigner: address is required");
|
|
70
|
+
}
|
|
71
|
+
const address = options.address;
|
|
72
|
+
const signatureFor = (signature) => ({
|
|
73
|
+
[address]: decodeSignature(signature)
|
|
74
|
+
});
|
|
75
|
+
function signMessages(messages, config) {
|
|
76
|
+
return __async(this, null, function* () {
|
|
77
|
+
if (!messages || messages.length === 0) {
|
|
78
|
+
throw new import__.ParaRestValidationError("ParaRestSolanaSigner: No messages provided to sign");
|
|
79
|
+
}
|
|
80
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, "before starting");
|
|
81
|
+
const signatures = [];
|
|
82
|
+
for (let i = 0; i < messages.length; i++) {
|
|
83
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, `while signing message ${i + 1} of ${messages.length}`);
|
|
84
|
+
const content = messages[i].content;
|
|
85
|
+
if (!content || content.length === 0) {
|
|
86
|
+
throw new import__.ParaRestValidationError(`ParaRestSolanaSigner: Message ${i + 1} has no content to sign`);
|
|
87
|
+
}
|
|
88
|
+
const response = yield options.client.signRaw(
|
|
89
|
+
options.walletId,
|
|
90
|
+
{
|
|
91
|
+
data: bytesToHex(content),
|
|
92
|
+
encoding: "hex",
|
|
93
|
+
walletType: "SOLANA"
|
|
94
|
+
},
|
|
95
|
+
callOptions(config)
|
|
96
|
+
);
|
|
97
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, `after signing message ${i + 1} of ${messages.length}`);
|
|
98
|
+
signatures.push(signatureFor(response.signature));
|
|
99
|
+
}
|
|
100
|
+
return signatures;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function signTransactions(transactions, config) {
|
|
104
|
+
return __async(this, null, function* () {
|
|
105
|
+
if (!transactions || transactions.length === 0) {
|
|
106
|
+
throw new import__.ParaRestValidationError("ParaRestSolanaSigner: No transactions provided to sign");
|
|
107
|
+
}
|
|
108
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, "before starting");
|
|
109
|
+
const signatures = [];
|
|
110
|
+
for (let i = 0; i < transactions.length; i++) {
|
|
111
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, `while signing transaction ${i + 1} of ${transactions.length}`);
|
|
112
|
+
const transaction = transactions[i];
|
|
113
|
+
if (!transaction.messageBytes || transaction.messageBytes.length === 0) {
|
|
114
|
+
throw new import__.ParaRestValidationError(`ParaRestSolanaSigner: Transaction ${i + 1} has no message bytes to sign`);
|
|
115
|
+
}
|
|
116
|
+
const response = yield options.client.signRaw(
|
|
117
|
+
options.walletId,
|
|
118
|
+
{
|
|
119
|
+
data: bytesToHex(transaction.messageBytes),
|
|
120
|
+
encoding: "hex",
|
|
121
|
+
walletType: "SOLANA"
|
|
122
|
+
},
|
|
123
|
+
callOptions(config)
|
|
124
|
+
);
|
|
125
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, `after signing transaction ${i + 1} of ${transactions.length}`);
|
|
126
|
+
signatures.push(signatureFor(response.signature));
|
|
127
|
+
}
|
|
128
|
+
return signatures;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
address,
|
|
133
|
+
signMessages,
|
|
134
|
+
signTransactions,
|
|
135
|
+
modifyAndSignMessages(messages, config) {
|
|
136
|
+
return __async(this, null, function* () {
|
|
137
|
+
const signatures = yield signMessages(messages, config);
|
|
138
|
+
return messages.map((message, index) => __spreadProps(__spreadValues({}, message), {
|
|
139
|
+
signatures: __spreadValues(__spreadValues({}, message.signatures), signatures[index])
|
|
140
|
+
}));
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
modifyAndSignTransactions(transactions, config) {
|
|
144
|
+
return __async(this, null, function* () {
|
|
145
|
+
const signatures = yield signTransactions(transactions, config);
|
|
146
|
+
return transactions.map(
|
|
147
|
+
(transaction, index) => __spreadProps(__spreadValues({}, transaction), {
|
|
148
|
+
signatures: __spreadValues(__spreadValues({}, transaction.signatures), signatures[index])
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function callOptions(config) {
|
|
156
|
+
return (config == null ? void 0 : config.abortSignal) ? { signal: config.abortSignal } : void 0;
|
|
157
|
+
}
|
|
158
|
+
function throwIfAborted(signal, when) {
|
|
159
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
160
|
+
throw new import__.ParaRestValidationError(`ParaRestSolanaSigner: Operation was aborted ${when}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function decodeSignature(value) {
|
|
164
|
+
const decoded = firstValidDecoded(value, [decodeHex, decodeBase64, decodeBase58], 64);
|
|
165
|
+
if (!decoded) {
|
|
166
|
+
throw new import__.ParaRestValidationError("ParaRestSolanaSigner: Expected a 64-byte Solana signature");
|
|
167
|
+
}
|
|
168
|
+
return decoded;
|
|
169
|
+
}
|
|
170
|
+
function firstValidDecoded(value, decoders, expectedLength) {
|
|
171
|
+
for (const decode of decoders) {
|
|
172
|
+
const bytes = decode(value);
|
|
173
|
+
if (bytes && (expectedLength == null || bytes.length === expectedLength)) {
|
|
174
|
+
return bytes;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
function bytesToHex(bytes) {
|
|
180
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
181
|
+
}
|
|
182
|
+
function decodeHex(value) {
|
|
183
|
+
const hex = value.startsWith("0x") || value.startsWith("0X") ? value.slice(2) : value;
|
|
184
|
+
if (hex.length === 0 || hex.length % 2 !== 0 || !/^[\da-f]+$/i.test(hex)) {
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
188
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
189
|
+
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
190
|
+
}
|
|
191
|
+
return bytes;
|
|
192
|
+
}
|
|
193
|
+
function decodeBase64(value) {
|
|
194
|
+
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
195
|
+
if (normalized.length % 4 === 1 || !/^[A-Za-z0-9+/]*={0,2}$/.test(normalized)) {
|
|
196
|
+
return void 0;
|
|
197
|
+
}
|
|
198
|
+
const padded = normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "=");
|
|
199
|
+
const globals = globalThis;
|
|
200
|
+
try {
|
|
201
|
+
if (globals.Buffer) {
|
|
202
|
+
return new Uint8Array(globals.Buffer.from(padded, "base64"));
|
|
203
|
+
}
|
|
204
|
+
if (globals.atob) {
|
|
205
|
+
return Uint8Array.from(globals.atob(padded), (char) => char.charCodeAt(0));
|
|
206
|
+
}
|
|
207
|
+
} catch (e) {
|
|
208
|
+
return void 0;
|
|
209
|
+
}
|
|
210
|
+
return void 0;
|
|
211
|
+
}
|
|
212
|
+
const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
213
|
+
function decodeBase58(value) {
|
|
214
|
+
if (!value) {
|
|
215
|
+
return void 0;
|
|
216
|
+
}
|
|
217
|
+
const bytes = [];
|
|
218
|
+
for (const char of value) {
|
|
219
|
+
const digit = BASE58_ALPHABET.indexOf(char);
|
|
220
|
+
if (digit === -1) {
|
|
221
|
+
return void 0;
|
|
222
|
+
}
|
|
223
|
+
let carry = digit;
|
|
224
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
225
|
+
carry += bytes[i] * 58;
|
|
226
|
+
bytes[i] = carry & 255;
|
|
227
|
+
carry >>= 8;
|
|
228
|
+
}
|
|
229
|
+
while (carry > 0) {
|
|
230
|
+
bytes.push(carry & 255);
|
|
231
|
+
carry >>= 8;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
let leadingZeroes = 0;
|
|
235
|
+
for (const char of value) {
|
|
236
|
+
if (char !== "1") {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
leadingZeroes++;
|
|
240
|
+
}
|
|
241
|
+
return new Uint8Array([...new Array(leadingZeroes).fill(0), ...bytes.reverse()]);
|
|
242
|
+
}
|
|
243
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
244
|
+
0 && (module.exports = {
|
|
245
|
+
createParaRestSolanaSigner
|
|
246
|
+
});
|