@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,225 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import { ParaRestValidationError } from "../index.js";
|
|
41
|
+
function createParaRestSolanaSigner(options) {
|
|
42
|
+
if (!options.client) {
|
|
43
|
+
throw new ParaRestValidationError("ParaRestSolanaSigner: client is required");
|
|
44
|
+
}
|
|
45
|
+
if (!options.walletId) {
|
|
46
|
+
throw new ParaRestValidationError("ParaRestSolanaSigner: walletId is required");
|
|
47
|
+
}
|
|
48
|
+
if (!options.address) {
|
|
49
|
+
throw new ParaRestValidationError("ParaRestSolanaSigner: address is required");
|
|
50
|
+
}
|
|
51
|
+
const address = options.address;
|
|
52
|
+
const signatureFor = (signature) => ({
|
|
53
|
+
[address]: decodeSignature(signature)
|
|
54
|
+
});
|
|
55
|
+
function signMessages(messages, config) {
|
|
56
|
+
return __async(this, null, function* () {
|
|
57
|
+
if (!messages || messages.length === 0) {
|
|
58
|
+
throw new ParaRestValidationError("ParaRestSolanaSigner: No messages provided to sign");
|
|
59
|
+
}
|
|
60
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, "before starting");
|
|
61
|
+
const signatures = [];
|
|
62
|
+
for (let i = 0; i < messages.length; i++) {
|
|
63
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, `while signing message ${i + 1} of ${messages.length}`);
|
|
64
|
+
const content = messages[i].content;
|
|
65
|
+
if (!content || content.length === 0) {
|
|
66
|
+
throw new ParaRestValidationError(`ParaRestSolanaSigner: Message ${i + 1} has no content to sign`);
|
|
67
|
+
}
|
|
68
|
+
const response = yield options.client.signRaw(
|
|
69
|
+
options.walletId,
|
|
70
|
+
{
|
|
71
|
+
data: bytesToHex(content),
|
|
72
|
+
encoding: "hex",
|
|
73
|
+
walletType: "SOLANA"
|
|
74
|
+
},
|
|
75
|
+
callOptions(config)
|
|
76
|
+
);
|
|
77
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, `after signing message ${i + 1} of ${messages.length}`);
|
|
78
|
+
signatures.push(signatureFor(response.signature));
|
|
79
|
+
}
|
|
80
|
+
return signatures;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function signTransactions(transactions, config) {
|
|
84
|
+
return __async(this, null, function* () {
|
|
85
|
+
if (!transactions || transactions.length === 0) {
|
|
86
|
+
throw new ParaRestValidationError("ParaRestSolanaSigner: No transactions provided to sign");
|
|
87
|
+
}
|
|
88
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, "before starting");
|
|
89
|
+
const signatures = [];
|
|
90
|
+
for (let i = 0; i < transactions.length; i++) {
|
|
91
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, `while signing transaction ${i + 1} of ${transactions.length}`);
|
|
92
|
+
const transaction = transactions[i];
|
|
93
|
+
if (!transaction.messageBytes || transaction.messageBytes.length === 0) {
|
|
94
|
+
throw new ParaRestValidationError(`ParaRestSolanaSigner: Transaction ${i + 1} has no message bytes to sign`);
|
|
95
|
+
}
|
|
96
|
+
const response = yield options.client.signRaw(
|
|
97
|
+
options.walletId,
|
|
98
|
+
{
|
|
99
|
+
data: bytesToHex(transaction.messageBytes),
|
|
100
|
+
encoding: "hex",
|
|
101
|
+
walletType: "SOLANA"
|
|
102
|
+
},
|
|
103
|
+
callOptions(config)
|
|
104
|
+
);
|
|
105
|
+
throwIfAborted(config == null ? void 0 : config.abortSignal, `after signing transaction ${i + 1} of ${transactions.length}`);
|
|
106
|
+
signatures.push(signatureFor(response.signature));
|
|
107
|
+
}
|
|
108
|
+
return signatures;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
address,
|
|
113
|
+
signMessages,
|
|
114
|
+
signTransactions,
|
|
115
|
+
modifyAndSignMessages(messages, config) {
|
|
116
|
+
return __async(this, null, function* () {
|
|
117
|
+
const signatures = yield signMessages(messages, config);
|
|
118
|
+
return messages.map((message, index) => __spreadProps(__spreadValues({}, message), {
|
|
119
|
+
signatures: __spreadValues(__spreadValues({}, message.signatures), signatures[index])
|
|
120
|
+
}));
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
modifyAndSignTransactions(transactions, config) {
|
|
124
|
+
return __async(this, null, function* () {
|
|
125
|
+
const signatures = yield signTransactions(transactions, config);
|
|
126
|
+
return transactions.map(
|
|
127
|
+
(transaction, index) => __spreadProps(__spreadValues({}, transaction), {
|
|
128
|
+
signatures: __spreadValues(__spreadValues({}, transaction.signatures), signatures[index])
|
|
129
|
+
})
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function callOptions(config) {
|
|
136
|
+
return (config == null ? void 0 : config.abortSignal) ? { signal: config.abortSignal } : void 0;
|
|
137
|
+
}
|
|
138
|
+
function throwIfAborted(signal, when) {
|
|
139
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
140
|
+
throw new ParaRestValidationError(`ParaRestSolanaSigner: Operation was aborted ${when}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function decodeSignature(value) {
|
|
144
|
+
const decoded = firstValidDecoded(value, [decodeHex, decodeBase64, decodeBase58], 64);
|
|
145
|
+
if (!decoded) {
|
|
146
|
+
throw new ParaRestValidationError("ParaRestSolanaSigner: Expected a 64-byte Solana signature");
|
|
147
|
+
}
|
|
148
|
+
return decoded;
|
|
149
|
+
}
|
|
150
|
+
function firstValidDecoded(value, decoders, expectedLength) {
|
|
151
|
+
for (const decode of decoders) {
|
|
152
|
+
const bytes = decode(value);
|
|
153
|
+
if (bytes && (expectedLength == null || bytes.length === expectedLength)) {
|
|
154
|
+
return bytes;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
function bytesToHex(bytes) {
|
|
160
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
161
|
+
}
|
|
162
|
+
function decodeHex(value) {
|
|
163
|
+
const hex = value.startsWith("0x") || value.startsWith("0X") ? value.slice(2) : value;
|
|
164
|
+
if (hex.length === 0 || hex.length % 2 !== 0 || !/^[\da-f]+$/i.test(hex)) {
|
|
165
|
+
return void 0;
|
|
166
|
+
}
|
|
167
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
168
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
169
|
+
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
170
|
+
}
|
|
171
|
+
return bytes;
|
|
172
|
+
}
|
|
173
|
+
function decodeBase64(value) {
|
|
174
|
+
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
175
|
+
if (normalized.length % 4 === 1 || !/^[A-Za-z0-9+/]*={0,2}$/.test(normalized)) {
|
|
176
|
+
return void 0;
|
|
177
|
+
}
|
|
178
|
+
const padded = normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "=");
|
|
179
|
+
const globals = globalThis;
|
|
180
|
+
try {
|
|
181
|
+
if (globals.Buffer) {
|
|
182
|
+
return new Uint8Array(globals.Buffer.from(padded, "base64"));
|
|
183
|
+
}
|
|
184
|
+
if (globals.atob) {
|
|
185
|
+
return Uint8Array.from(globals.atob(padded), (char) => char.charCodeAt(0));
|
|
186
|
+
}
|
|
187
|
+
} catch (e) {
|
|
188
|
+
return void 0;
|
|
189
|
+
}
|
|
190
|
+
return void 0;
|
|
191
|
+
}
|
|
192
|
+
const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
193
|
+
function decodeBase58(value) {
|
|
194
|
+
if (!value) {
|
|
195
|
+
return void 0;
|
|
196
|
+
}
|
|
197
|
+
const bytes = [];
|
|
198
|
+
for (const char of value) {
|
|
199
|
+
const digit = BASE58_ALPHABET.indexOf(char);
|
|
200
|
+
if (digit === -1) {
|
|
201
|
+
return void 0;
|
|
202
|
+
}
|
|
203
|
+
let carry = digit;
|
|
204
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
205
|
+
carry += bytes[i] * 58;
|
|
206
|
+
bytes[i] = carry & 255;
|
|
207
|
+
carry >>= 8;
|
|
208
|
+
}
|
|
209
|
+
while (carry > 0) {
|
|
210
|
+
bytes.push(carry & 255);
|
|
211
|
+
carry >>= 8;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
let leadingZeroes = 0;
|
|
215
|
+
for (const char of value) {
|
|
216
|
+
if (char !== "1") {
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
leadingZeroes++;
|
|
220
|
+
}
|
|
221
|
+
return new Uint8Array([...new Array(leadingZeroes).fill(0), ...bytes.reverse()]);
|
|
222
|
+
}
|
|
223
|
+
export {
|
|
224
|
+
createParaRestSolanaSigner
|
|
225
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __async = (__this, __arguments, generator) => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
var fulfilled = (value) => {
|
|
20
|
+
try {
|
|
21
|
+
step(generator.next(value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var rejected = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.throw(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
import { hashMessage, parseSignature, serializeSignature } from "viem";
|
|
38
|
+
import { ParaRestValidationError } from "../index.js";
|
|
39
|
+
function createParaRestViemAccount(options) {
|
|
40
|
+
const { client, walletId, address, publicKey = "0x" } = options;
|
|
41
|
+
return {
|
|
42
|
+
address,
|
|
43
|
+
publicKey,
|
|
44
|
+
source: "custom",
|
|
45
|
+
type: "local",
|
|
46
|
+
sign: (_0) => __async(this, [_0], function* ({ hash }) {
|
|
47
|
+
const res = yield client.signRaw(walletId, {
|
|
48
|
+
data: hash,
|
|
49
|
+
encoding: "hex",
|
|
50
|
+
walletType: "EVM"
|
|
51
|
+
});
|
|
52
|
+
return normalizeSignature(res.signature);
|
|
53
|
+
}),
|
|
54
|
+
signMessage: (_0) => __async(this, [_0], function* ({ message }) {
|
|
55
|
+
if (typeof message !== "string") {
|
|
56
|
+
const res2 = yield client.signRaw(walletId, {
|
|
57
|
+
data: hashMessage(message),
|
|
58
|
+
encoding: "hex",
|
|
59
|
+
walletType: "EVM"
|
|
60
|
+
});
|
|
61
|
+
return normalizeSignature(res2.signature);
|
|
62
|
+
}
|
|
63
|
+
const res = yield client.signMessage(walletId, { message });
|
|
64
|
+
return normalizeSignature(res.signature);
|
|
65
|
+
}),
|
|
66
|
+
signTypedData: (typedDataDefinition) => __async(this, null, function* () {
|
|
67
|
+
const res = yield client.signTypedData(walletId, {
|
|
68
|
+
typedData: toRestTypedData(typedDataDefinition)
|
|
69
|
+
});
|
|
70
|
+
return normalizeSignature(res.signature);
|
|
71
|
+
}),
|
|
72
|
+
signTransaction: (transaction, args) => __async(this, null, function* () {
|
|
73
|
+
if (args == null ? void 0 : args.serializer) {
|
|
74
|
+
throw new ParaRestValidationError("custom transaction serializers are not supported by the REST signer");
|
|
75
|
+
}
|
|
76
|
+
const res = yield client.signTransaction(walletId, {
|
|
77
|
+
transaction: toRestTransaction(transaction)
|
|
78
|
+
});
|
|
79
|
+
return res.signedTransaction;
|
|
80
|
+
}),
|
|
81
|
+
signAuthorization: (authorization) => __async(this, null, function* () {
|
|
82
|
+
const res = yield client.signAuthorization(walletId, {
|
|
83
|
+
authorization
|
|
84
|
+
});
|
|
85
|
+
const parsed = parseSignature(toHexSignature(res.signature));
|
|
86
|
+
return {
|
|
87
|
+
address: res.address,
|
|
88
|
+
chainId: res.chainId,
|
|
89
|
+
nonce: res.nonce,
|
|
90
|
+
r: parsed.r,
|
|
91
|
+
s: parsed.s,
|
|
92
|
+
yParity: parsed.yParity
|
|
93
|
+
};
|
|
94
|
+
})
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function normalizeSignature(signature) {
|
|
98
|
+
const parsed = parseSignature(toHexSignature(signature));
|
|
99
|
+
return serializeSignature({ r: parsed.r, s: parsed.s, yParity: parsed.yParity });
|
|
100
|
+
}
|
|
101
|
+
function toHexSignature(signature) {
|
|
102
|
+
return signature.startsWith("0x") ? signature : `0x${signature}`;
|
|
103
|
+
}
|
|
104
|
+
function toRestTransaction(transaction) {
|
|
105
|
+
if (!transaction.to) {
|
|
106
|
+
throw new ParaRestValidationError("transaction.to is required");
|
|
107
|
+
}
|
|
108
|
+
if (transaction.chainId == null) {
|
|
109
|
+
throw new ParaRestValidationError("transaction.chainId is required");
|
|
110
|
+
}
|
|
111
|
+
if (transaction.accessList != null) {
|
|
112
|
+
throw new ParaRestValidationError("transaction.accessList is not supported by the REST signer");
|
|
113
|
+
}
|
|
114
|
+
const type = restTransactionType(transaction);
|
|
115
|
+
return omitUndefined({
|
|
116
|
+
to: transaction.to,
|
|
117
|
+
value: quantity(transaction.value),
|
|
118
|
+
chainId: quantity(transaction.chainId),
|
|
119
|
+
data: transaction.data,
|
|
120
|
+
nonce: transaction.nonce,
|
|
121
|
+
gasLimit: quantity(transaction.gas),
|
|
122
|
+
maxFeePerGas: quantity(transaction.maxFeePerGas),
|
|
123
|
+
maxPriorityFeePerGas: quantity(transaction.maxPriorityFeePerGas),
|
|
124
|
+
gasPrice: quantity(transaction.gasPrice),
|
|
125
|
+
type
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function toRestTypedData(typedData) {
|
|
129
|
+
var _a;
|
|
130
|
+
const types = __spreadValues({}, typedData.types);
|
|
131
|
+
delete types.EIP712Domain;
|
|
132
|
+
return {
|
|
133
|
+
domain: (_a = typedData.domain) != null ? _a : {},
|
|
134
|
+
types,
|
|
135
|
+
primaryType: typedData.primaryType,
|
|
136
|
+
message: typedData.message
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function restTransactionType(transaction) {
|
|
140
|
+
const { type } = transaction;
|
|
141
|
+
if (type === "legacy") return 0;
|
|
142
|
+
if (type === "eip1559") return 2;
|
|
143
|
+
if (type !== void 0) {
|
|
144
|
+
throw new ParaRestValidationError(`transaction.type ${String(type)} is not supported by the REST signer`);
|
|
145
|
+
}
|
|
146
|
+
if (transaction.maxFeePerGas != null || transaction.maxPriorityFeePerGas != null) return 2;
|
|
147
|
+
return transaction.gasPrice == null ? 2 : 0;
|
|
148
|
+
}
|
|
149
|
+
function quantity(value) {
|
|
150
|
+
return value == null ? void 0 : value.toString();
|
|
151
|
+
}
|
|
152
|
+
function omitUndefined(value) {
|
|
153
|
+
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0));
|
|
154
|
+
}
|
|
155
|
+
export {
|
|
156
|
+
createParaRestViemAccount
|
|
157
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import type { ParaRestClient } from '../index.js';
|
|
3
|
+
export interface CreateParaRestEthersSignerOptions {
|
|
4
|
+
client: ParaRestClient;
|
|
5
|
+
walletId: string;
|
|
6
|
+
address?: string;
|
|
7
|
+
provider?: ethers.Provider | null;
|
|
8
|
+
}
|
|
9
|
+
export declare class ParaRestEthersSigner extends ethers.AbstractSigner {
|
|
10
|
+
private readonly client;
|
|
11
|
+
private readonly walletId;
|
|
12
|
+
private readonly initialAddress?;
|
|
13
|
+
private cachedWallet?;
|
|
14
|
+
constructor({ client, walletId, address, provider }: CreateParaRestEthersSignerOptions);
|
|
15
|
+
connect(provider: ethers.Provider | null): ParaRestEthersSigner;
|
|
16
|
+
getAddress(): Promise<string>;
|
|
17
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
18
|
+
signTransaction(tx: ethers.TransactionRequest): Promise<string>;
|
|
19
|
+
signTypedData(domain: ethers.TypedDataDomain, types: Record<string, Array<ethers.TypedDataField>>, value: Record<string, unknown>): Promise<string>;
|
|
20
|
+
private toRestTransaction;
|
|
21
|
+
}
|
|
22
|
+
export declare function createParaRestEthersSigner(options: CreateParaRestEthersSignerOptions): ParaRestEthersSigner;
|
|
23
|
+
export declare function normalizeEvmSignature(signature: string): string;
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import type { TPregenIdentifierType, TWalletScheme, TWalletType } from '@getpara/shared';
|
|
2
|
+
export type ParaRestEnvironment = 'PROD' | 'BETA' | 'SANDBOX' | {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
};
|
|
5
|
+
export type WalletType = TWalletType;
|
|
6
|
+
export type WalletScheme = TWalletScheme;
|
|
7
|
+
export type UserIdentifierType = TPregenIdentifierType;
|
|
8
|
+
export interface RestWallet {
|
|
9
|
+
id: string;
|
|
10
|
+
type: WalletType;
|
|
11
|
+
scheme: WalletScheme;
|
|
12
|
+
status: 'creating' | 'ready';
|
|
13
|
+
address?: string;
|
|
14
|
+
publicKey?: string;
|
|
15
|
+
userIdentifier?: string;
|
|
16
|
+
userIdentifierType?: UserIdentifierType;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RestPagination {
|
|
20
|
+
cursor: string | null;
|
|
21
|
+
hasMore: boolean;
|
|
22
|
+
limit: number;
|
|
23
|
+
}
|
|
24
|
+
export interface RestListResponse<T> {
|
|
25
|
+
data: T[];
|
|
26
|
+
pagination: RestPagination;
|
|
27
|
+
}
|
|
28
|
+
export interface CreateWalletRequest {
|
|
29
|
+
type: WalletType;
|
|
30
|
+
userIdentifier: string;
|
|
31
|
+
userIdentifierType: UserIdentifierType;
|
|
32
|
+
scheme?: WalletScheme;
|
|
33
|
+
cosmosPrefix?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ListWalletsRequest {
|
|
36
|
+
userIdentifier?: string;
|
|
37
|
+
userIdentifierType?: UserIdentifierType;
|
|
38
|
+
type?: WalletType;
|
|
39
|
+
status?: 'creating' | 'ready';
|
|
40
|
+
address?: string;
|
|
41
|
+
limit?: number;
|
|
42
|
+
cursor?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface UpdateWalletIdentifierRequest {
|
|
45
|
+
userIdentifier: string;
|
|
46
|
+
userIdentifierType: UserIdentifierType;
|
|
47
|
+
}
|
|
48
|
+
export interface MigrateShareRequest {
|
|
49
|
+
encryptedPayload: string;
|
|
50
|
+
}
|
|
51
|
+
export interface EnclavePublicKeyResponse {
|
|
52
|
+
publicKey: string;
|
|
53
|
+
keyFingerprint: string;
|
|
54
|
+
generatedAt: string;
|
|
55
|
+
}
|
|
56
|
+
export type SolanaNetwork = 'SOLANA' | 'SOLANA_DEVNET';
|
|
57
|
+
export interface GetWalletBalanceRequest {
|
|
58
|
+
chainId?: string | number;
|
|
59
|
+
tokenAddress?: string;
|
|
60
|
+
network?: SolanaNetwork;
|
|
61
|
+
}
|
|
62
|
+
export interface WalletBalanceResponse {
|
|
63
|
+
balance: string;
|
|
64
|
+
symbol: string;
|
|
65
|
+
rawBalance: string;
|
|
66
|
+
}
|
|
67
|
+
export interface SignRawRequest {
|
|
68
|
+
data: string;
|
|
69
|
+
encoding?: 'hex';
|
|
70
|
+
walletType?: WalletType;
|
|
71
|
+
}
|
|
72
|
+
export interface SignRawResponse {
|
|
73
|
+
signature: string;
|
|
74
|
+
}
|
|
75
|
+
export interface SignMessageRequest {
|
|
76
|
+
message: string;
|
|
77
|
+
}
|
|
78
|
+
export interface SignMessageResponse {
|
|
79
|
+
signature: string;
|
|
80
|
+
}
|
|
81
|
+
export interface SignTransactionRequest {
|
|
82
|
+
transaction: EvmSignTransactionRequest | string;
|
|
83
|
+
broadcast?: boolean;
|
|
84
|
+
network?: SolanaNetwork;
|
|
85
|
+
networkPassphrase?: string;
|
|
86
|
+
}
|
|
87
|
+
export interface EvmSignTransactionRequest {
|
|
88
|
+
to: string;
|
|
89
|
+
chainId: string | number;
|
|
90
|
+
type: 0 | 2;
|
|
91
|
+
value?: string;
|
|
92
|
+
data?: string;
|
|
93
|
+
nonce?: number;
|
|
94
|
+
gasLimit?: string;
|
|
95
|
+
maxFeePerGas?: string;
|
|
96
|
+
maxPriorityFeePerGas?: string;
|
|
97
|
+
gasPrice?: string;
|
|
98
|
+
}
|
|
99
|
+
export interface SignTransactionResponse {
|
|
100
|
+
signedTransaction: string;
|
|
101
|
+
txHash?: string;
|
|
102
|
+
transactionId?: string;
|
|
103
|
+
}
|
|
104
|
+
export interface TypedDataPayload {
|
|
105
|
+
domain: Record<string, unknown>;
|
|
106
|
+
types: Record<string, Array<{
|
|
107
|
+
name: string;
|
|
108
|
+
type: string;
|
|
109
|
+
}>>;
|
|
110
|
+
primaryType: string;
|
|
111
|
+
message: Record<string, unknown>;
|
|
112
|
+
}
|
|
113
|
+
export interface SignTypedDataRequest {
|
|
114
|
+
typedData: TypedDataPayload;
|
|
115
|
+
}
|
|
116
|
+
export interface SignTypedDataResponse {
|
|
117
|
+
signature: string;
|
|
118
|
+
}
|
|
119
|
+
export interface SignAuthorizationRequest {
|
|
120
|
+
authorization: SignAuthorizationPayload;
|
|
121
|
+
}
|
|
122
|
+
export type SignAuthorizationPayload = ({
|
|
123
|
+
contractAddress: string;
|
|
124
|
+
address?: string;
|
|
125
|
+
} | {
|
|
126
|
+
address: string;
|
|
127
|
+
contractAddress?: string;
|
|
128
|
+
}) & {
|
|
129
|
+
chainId: string | number;
|
|
130
|
+
nonce: number;
|
|
131
|
+
};
|
|
132
|
+
export interface SignAuthorizationResponse {
|
|
133
|
+
address: string;
|
|
134
|
+
chainId: number;
|
|
135
|
+
nonce: number;
|
|
136
|
+
r: string;
|
|
137
|
+
s: string;
|
|
138
|
+
yParity: 0 | 1;
|
|
139
|
+
signature: string;
|
|
140
|
+
}
|
|
141
|
+
export interface TransferRequest {
|
|
142
|
+
to: string;
|
|
143
|
+
value: string;
|
|
144
|
+
chainId?: string | number;
|
|
145
|
+
tokenAddress?: string;
|
|
146
|
+
nonce?: number;
|
|
147
|
+
gasLimit?: string;
|
|
148
|
+
maxFeePerGas?: string;
|
|
149
|
+
maxPriorityFeePerGas?: string;
|
|
150
|
+
gasPrice?: string;
|
|
151
|
+
type?: 0 | 2;
|
|
152
|
+
kind?: 'NATIVE' | 'ERC20' | 'SPL';
|
|
153
|
+
broadcast?: boolean;
|
|
154
|
+
network?: SolanaNetwork;
|
|
155
|
+
}
|
|
156
|
+
export interface TransferResponse {
|
|
157
|
+
signedTransaction: string;
|
|
158
|
+
txHash?: string;
|
|
159
|
+
transactionId?: string;
|
|
160
|
+
}
|
|
161
|
+
export interface EstimateFeeRequest {
|
|
162
|
+
to: string;
|
|
163
|
+
value: string;
|
|
164
|
+
chainId?: string | number;
|
|
165
|
+
tokenAddress?: string;
|
|
166
|
+
network?: SolanaNetwork;
|
|
167
|
+
}
|
|
168
|
+
export interface EstimateFeeResponse {
|
|
169
|
+
estimatedFee: string;
|
|
170
|
+
transferAmount: string;
|
|
171
|
+
currency: string;
|
|
172
|
+
gasLimit?: string;
|
|
173
|
+
maxFeePerGas?: string;
|
|
174
|
+
maxPriorityFeePerGas?: string;
|
|
175
|
+
gasPrice?: string;
|
|
176
|
+
warning?: string;
|
|
177
|
+
}
|
|
178
|
+
export interface FaucetRequest {
|
|
179
|
+
walletId: string;
|
|
180
|
+
chain?: string;
|
|
181
|
+
}
|
|
182
|
+
export interface FaucetResponse {
|
|
183
|
+
transactionHash: string;
|
|
184
|
+
amount: string;
|
|
185
|
+
chain: string;
|
|
186
|
+
walletId: string;
|
|
187
|
+
address: string;
|
|
188
|
+
}
|
|
189
|
+
export type RestTransactionKnownStatus = 'pending' | 'submitted' | 'confirmed' | 'reverted' | 'failed';
|
|
190
|
+
export type RestTransactionStatus = RestTransactionKnownStatus | (string & {});
|
|
191
|
+
export type RestTransactionIntentKind = 'transfer' | 'sign_transaction';
|
|
192
|
+
export type RestTransactionFailureStage = 'mpc_sign' | 'signature_apply' | 'signer_verify' | 'broadcast' | 'monitor_timeout';
|
|
193
|
+
export type RestTransactionWalletType = 'EVM' | 'SOLANA';
|
|
194
|
+
export interface ListRestTransactionsRequest {
|
|
195
|
+
limit?: number;
|
|
196
|
+
cursor?: string;
|
|
197
|
+
status?: RestTransactionKnownStatus;
|
|
198
|
+
intentKind?: RestTransactionIntentKind;
|
|
199
|
+
}
|
|
200
|
+
export interface RestTransaction {
|
|
201
|
+
transactionId: string;
|
|
202
|
+
walletId: string;
|
|
203
|
+
walletType: RestTransactionWalletType;
|
|
204
|
+
intentKind: RestTransactionIntentKind;
|
|
205
|
+
status: RestTransactionStatus;
|
|
206
|
+
chainId?: string;
|
|
207
|
+
network?: SolanaNetwork;
|
|
208
|
+
to?: string;
|
|
209
|
+
value?: string;
|
|
210
|
+
tokenAddress?: string;
|
|
211
|
+
hash?: string;
|
|
212
|
+
blockNumber?: string;
|
|
213
|
+
blockHash?: string;
|
|
214
|
+
failureStage?: RestTransactionFailureStage;
|
|
215
|
+
failureCode?: string;
|
|
216
|
+
failureMessage?: string;
|
|
217
|
+
createdAt: string;
|
|
218
|
+
submittedAt?: string;
|
|
219
|
+
resolvedAt?: string;
|
|
220
|
+
}
|
|
221
|
+
export interface ParaRestCallOptions {
|
|
222
|
+
idempotencyKey?: string;
|
|
223
|
+
signal?: AbortSignal;
|
|
224
|
+
}
|
|
225
|
+
export interface ParaRestClientOptions {
|
|
226
|
+
apiKey: string;
|
|
227
|
+
env?: ParaRestEnvironment;
|
|
228
|
+
fetch?: RestFetch;
|
|
229
|
+
requestIdGenerator?: () => string;
|
|
230
|
+
}
|
|
231
|
+
export interface RestFetchInit {
|
|
232
|
+
method: string;
|
|
233
|
+
headers: Record<string, string>;
|
|
234
|
+
body?: string;
|
|
235
|
+
signal?: AbortSignal;
|
|
236
|
+
}
|
|
237
|
+
export interface RestHeaders {
|
|
238
|
+
get(name: string): string | null;
|
|
239
|
+
}
|
|
240
|
+
export interface RestFetchResponse {
|
|
241
|
+
ok: boolean;
|
|
242
|
+
status: number;
|
|
243
|
+
statusText?: string;
|
|
244
|
+
headers: RestHeaders;
|
|
245
|
+
text(): Promise<string>;
|
|
246
|
+
}
|
|
247
|
+
export type RestFetch = (input: string, init: RestFetchInit) => Promise<RestFetchResponse>;
|
|
248
|
+
export declare class ParaRestError extends Error {
|
|
249
|
+
readonly status: number;
|
|
250
|
+
readonly code?: string;
|
|
251
|
+
readonly requestId?: string;
|
|
252
|
+
readonly body: unknown;
|
|
253
|
+
constructor({ status, code, requestId, body, message, }: {
|
|
254
|
+
status: number;
|
|
255
|
+
code?: string;
|
|
256
|
+
requestId?: string;
|
|
257
|
+
body: unknown;
|
|
258
|
+
message?: string;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
export declare class ParaRestSerializationError extends Error {
|
|
262
|
+
constructor(message: string);
|
|
263
|
+
}
|
|
264
|
+
export declare class ParaRestValidationError extends Error {
|
|
265
|
+
constructor(message: string);
|
|
266
|
+
}
|
|
267
|
+
export declare function toRestJson(body: unknown): string;
|
|
268
|
+
export declare class ParaRestClient {
|
|
269
|
+
private readonly apiKey;
|
|
270
|
+
private readonly baseUrl;
|
|
271
|
+
private readonly fetchImpl;
|
|
272
|
+
private readonly requestIdGenerator;
|
|
273
|
+
constructor(options: ParaRestClientOptions);
|
|
274
|
+
createWallet(body: CreateWalletRequest, options?: ParaRestCallOptions): Promise<RestWallet>;
|
|
275
|
+
listWallets(query?: ListWalletsRequest, options?: ParaRestCallOptions): Promise<RestListResponse<RestWallet>>;
|
|
276
|
+
getWallet(walletId: string, options?: ParaRestCallOptions): Promise<RestWallet>;
|
|
277
|
+
updateWalletIdentifier(walletId: string, body: UpdateWalletIdentifierRequest, options?: ParaRestCallOptions): Promise<RestWallet>;
|
|
278
|
+
migrateShare(walletId: string, body: MigrateShareRequest, options?: ParaRestCallOptions): Promise<RestWallet>;
|
|
279
|
+
getEnclavePublicKey(options?: ParaRestCallOptions): Promise<EnclavePublicKeyResponse>;
|
|
280
|
+
getWalletBalance(walletId: string, query?: GetWalletBalanceRequest, options?: ParaRestCallOptions): Promise<WalletBalanceResponse>;
|
|
281
|
+
signRaw(walletId: string, body: SignRawRequest, options?: ParaRestCallOptions): Promise<SignRawResponse>;
|
|
282
|
+
signMessage(walletId: string, body: SignMessageRequest, options?: ParaRestCallOptions): Promise<SignMessageResponse>;
|
|
283
|
+
signTransaction(walletId: string, body: SignTransactionRequest, options?: ParaRestCallOptions): Promise<SignTransactionResponse>;
|
|
284
|
+
signTypedData(walletId: string, body: SignTypedDataRequest, options?: ParaRestCallOptions): Promise<SignTypedDataResponse>;
|
|
285
|
+
signAuthorization(walletId: string, body: SignAuthorizationRequest, options?: ParaRestCallOptions): Promise<SignAuthorizationResponse>;
|
|
286
|
+
transfer(walletId: string, body: TransferRequest, options?: ParaRestCallOptions): Promise<TransferResponse>;
|
|
287
|
+
estimateFee(walletId: string, body: EstimateFeeRequest, options?: ParaRestCallOptions): Promise<EstimateFeeResponse>;
|
|
288
|
+
requestFaucet(body: FaucetRequest, options?: ParaRestCallOptions): Promise<FaucetResponse>;
|
|
289
|
+
listRestTransactions(walletId: string, query?: ListRestTransactionsRequest, options?: ParaRestCallOptions): Promise<RestListResponse<RestTransaction>>;
|
|
290
|
+
getRestTransaction(walletId: string, transactionId: string, options?: ParaRestCallOptions): Promise<RestTransaction>;
|
|
291
|
+
private request;
|
|
292
|
+
}
|