@getpara/solana-signers-v2-integration 2.0.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/solanaSigner.js +265 -0
- package/dist/cjs/types.js +15 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/solanaSigner.js +234 -0
- package/dist/esm/types.js +0 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/solanaSigner.d.ts +62 -0
- package/dist/types/types.d.ts +14 -0
- package/package.json +47 -0
|
@@ -0,0 +1,36 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var src_exports = {};
|
|
20
|
+
__export(src_exports, {
|
|
21
|
+
ParaSolanaSigner: () => import_solanaSigner.ParaSolanaSigner,
|
|
22
|
+
createParaSolanaSigner: () => createParaSolanaSigner
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(src_exports);
|
|
25
|
+
var import_solanaSigner = require("./solanaSigner.js");
|
|
26
|
+
__reExport(src_exports, require("./types.js"), module.exports);
|
|
27
|
+
var import_solanaSigner2 = require("./solanaSigner.js");
|
|
28
|
+
function createParaSolanaSigner(params) {
|
|
29
|
+
return new import_solanaSigner2.ParaSolanaSigner(params);
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
ParaSolanaSigner,
|
|
34
|
+
createParaSolanaSigner,
|
|
35
|
+
...require("./types.js")
|
|
36
|
+
});
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
41
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
42
|
+
mod
|
|
43
|
+
));
|
|
44
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
var __async = (__this, __arguments, generator) => {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
var fulfilled = (value) => {
|
|
48
|
+
try {
|
|
49
|
+
step(generator.next(value));
|
|
50
|
+
} catch (e) {
|
|
51
|
+
reject(e);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var rejected = (value) => {
|
|
55
|
+
try {
|
|
56
|
+
step(generator.throw(value));
|
|
57
|
+
} catch (e) {
|
|
58
|
+
reject(e);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
62
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
var solanaSigner_exports = {};
|
|
66
|
+
__export(solanaSigner_exports, {
|
|
67
|
+
ParaSolanaSigner: () => ParaSolanaSigner
|
|
68
|
+
});
|
|
69
|
+
module.exports = __toCommonJS(solanaSigner_exports);
|
|
70
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
71
|
+
var import_transactions = require("@solana/transactions");
|
|
72
|
+
var import_addresses = require("@solana/addresses");
|
|
73
|
+
var import_bs58 = __toESM(require("bs58"));
|
|
74
|
+
class ParaSolanaSigner {
|
|
75
|
+
constructor(params) {
|
|
76
|
+
var _a;
|
|
77
|
+
if (!params.para) {
|
|
78
|
+
throw new Error("ParaSolanaSigner: `para` parameter is required");
|
|
79
|
+
}
|
|
80
|
+
if (!params.rpc) {
|
|
81
|
+
throw new Error("ParaSolanaSigner: `rpc` parameter is required");
|
|
82
|
+
}
|
|
83
|
+
this.para = params.para;
|
|
84
|
+
this.rpc = params.rpc;
|
|
85
|
+
try {
|
|
86
|
+
this.walletId = params.para.findWalletId(params.walletId, { type: ["SOLANA"] });
|
|
87
|
+
} catch (error) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`ParaSolanaSigner: Failed to find Solana wallet. ${error instanceof Error ? error.message : "Unknown error"}`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (!((_a = params.para.wallets[this.walletId]) == null ? void 0 : _a.address)) {
|
|
93
|
+
throw new Error("ParaSolanaSigner: Wallet address not found");
|
|
94
|
+
}
|
|
95
|
+
this.address = params.para.wallets[this.walletId].address;
|
|
96
|
+
this.sender = new Uint8Array((0, import_addresses.getAddressEncoder)().encode(this.address));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Sign one or more transactions
|
|
100
|
+
* @param transactions - Array of transactions to sign
|
|
101
|
+
* @param config - Optional configuration including abort signal
|
|
102
|
+
* @returns Array of signature dictionaries
|
|
103
|
+
*/
|
|
104
|
+
signTransactions(transactions, config) {
|
|
105
|
+
return __async(this, null, function* () {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
if (!transactions || transactions.length === 0) {
|
|
108
|
+
throw new Error("ParaSolanaSigner: No transactions provided to sign");
|
|
109
|
+
}
|
|
110
|
+
if ((_a = config == null ? void 0 : config.abortSignal) == null ? void 0 : _a.aborted) {
|
|
111
|
+
throw new Error("ParaSolanaSigner: Operation was aborted before starting");
|
|
112
|
+
}
|
|
113
|
+
const signatures = [];
|
|
114
|
+
for (let i = 0; i < transactions.length; i++) {
|
|
115
|
+
const transaction = transactions[i];
|
|
116
|
+
if ((_b = config == null ? void 0 : config.abortSignal) == null ? void 0 : _b.aborted) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`ParaSolanaSigner: Operation was aborted while signing transaction ${i + 1} of ${transactions.length}`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (!transaction.messageBytes || transaction.messageBytes.length === 0) {
|
|
122
|
+
throw new Error(`ParaSolanaSigner: Transaction ${i + 1} has no message bytes to sign`);
|
|
123
|
+
}
|
|
124
|
+
const messageBase64 = Buffer.from(transaction.messageBytes).toString("base64");
|
|
125
|
+
try {
|
|
126
|
+
const res = yield this.para.signMessage({
|
|
127
|
+
walletId: this.walletId,
|
|
128
|
+
messageBase64
|
|
129
|
+
});
|
|
130
|
+
if (res.transactionReviewUrl) {
|
|
131
|
+
throw new import_core_sdk.TransactionReviewError(res.transactionReviewUrl);
|
|
132
|
+
}
|
|
133
|
+
const signatureBytes = Buffer.from(res.signature, "base64");
|
|
134
|
+
const signatureDictionary = {
|
|
135
|
+
[this.address]: signatureBytes
|
|
136
|
+
};
|
|
137
|
+
signatures.push(signatureDictionary);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if (error instanceof import_core_sdk.TransactionReviewError) {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
throw new Error(
|
|
143
|
+
`ParaSolanaSigner: Failed to sign transaction ${i + 1}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return signatures;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
modifyAndSignTransactions(transactions, config) {
|
|
151
|
+
return __async(this, null, function* () {
|
|
152
|
+
const signatureDictionaries = yield this.signTransactions(transactions, config);
|
|
153
|
+
const signedTransactions = transactions.map((transaction, index) => {
|
|
154
|
+
const signatureDictionary = signatureDictionaries[index];
|
|
155
|
+
const existingSignatures = transaction.signatures || {};
|
|
156
|
+
return __spreadProps(__spreadValues({}, transaction), {
|
|
157
|
+
signatures: __spreadValues(__spreadValues({}, existingSignatures), signatureDictionary)
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
return signedTransactions;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Sign and send transactions to the network
|
|
165
|
+
* @param transactions - Array of transactions to sign and send
|
|
166
|
+
* @param config - Optional configuration including abort signal
|
|
167
|
+
* @returns Array of transaction signatures
|
|
168
|
+
* @throws Error if no RPC client is configured
|
|
169
|
+
*/
|
|
170
|
+
signAndSendTransactions(transactions, config) {
|
|
171
|
+
return __async(this, null, function* () {
|
|
172
|
+
var _a;
|
|
173
|
+
if (!transactions || transactions.length === 0) {
|
|
174
|
+
throw new Error("ParaSolanaSigner: No transactions provided to send");
|
|
175
|
+
}
|
|
176
|
+
const signedTransactions = yield this.modifyAndSignTransactions(transactions, config);
|
|
177
|
+
const sentSignatures = [];
|
|
178
|
+
for (let i = 0; i < signedTransactions.length; i++) {
|
|
179
|
+
const signedTransaction = signedTransactions[i];
|
|
180
|
+
if ((_a = config == null ? void 0 : config.abortSignal) == null ? void 0 : _a.aborted) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
`ParaSolanaSigner: Operation was aborted while sending transaction ${i + 1} of ${signedTransactions.length}`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
const serializedTransaction = (0, import_transactions.getBase64EncodedWireTransaction)(signedTransaction);
|
|
187
|
+
const signatureBase58 = yield this.rpc.sendTransaction(serializedTransaction, {
|
|
188
|
+
encoding: "base64",
|
|
189
|
+
skipPreflight: false,
|
|
190
|
+
preflightCommitment: "processed"
|
|
191
|
+
}).send({ abortSignal: config == null ? void 0 : config.abortSignal });
|
|
192
|
+
const signatureBytes = import_bs58.default.decode(signatureBase58);
|
|
193
|
+
sentSignatures.push(signatureBytes);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`ParaSolanaSigner: Failed to send transaction ${i + 1}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return sentSignatures;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Sign one or more messages
|
|
205
|
+
* @param messages - Array of messages to sign
|
|
206
|
+
* @param config - Optional configuration including abort signal
|
|
207
|
+
* @returns Array of signature dictionaries
|
|
208
|
+
*/
|
|
209
|
+
signMessages(messages, config) {
|
|
210
|
+
return __async(this, null, function* () {
|
|
211
|
+
var _a, _b;
|
|
212
|
+
if (!messages || messages.length === 0) {
|
|
213
|
+
throw new Error("ParaSolanaSigner: No messages provided to sign");
|
|
214
|
+
}
|
|
215
|
+
if ((_a = config == null ? void 0 : config.abortSignal) == null ? void 0 : _a.aborted) {
|
|
216
|
+
throw new Error("ParaSolanaSigner: Operation was aborted before starting");
|
|
217
|
+
}
|
|
218
|
+
const signatures = [];
|
|
219
|
+
for (let i = 0; i < messages.length; i++) {
|
|
220
|
+
const message = messages[i];
|
|
221
|
+
if ((_b = config == null ? void 0 : config.abortSignal) == null ? void 0 : _b.aborted) {
|
|
222
|
+
throw new Error(`ParaSolanaSigner: Operation was aborted while signing message ${i + 1} of ${messages.length}`);
|
|
223
|
+
}
|
|
224
|
+
if (!message.content || message.content.length === 0) {
|
|
225
|
+
throw new Error(`ParaSolanaSigner: Message ${i + 1} has no content to sign`);
|
|
226
|
+
}
|
|
227
|
+
const messageBase64 = Buffer.from(message.content).toString("base64");
|
|
228
|
+
try {
|
|
229
|
+
const res = yield this.para.signMessage({
|
|
230
|
+
walletId: this.walletId,
|
|
231
|
+
messageBase64
|
|
232
|
+
});
|
|
233
|
+
if (res.transactionReviewUrl) {
|
|
234
|
+
throw new import_core_sdk.TransactionReviewError(res.transactionReviewUrl);
|
|
235
|
+
}
|
|
236
|
+
const signatureBytes = Buffer.from(res.signature, "base64");
|
|
237
|
+
const signatureDictionary = {
|
|
238
|
+
[this.address]: signatureBytes
|
|
239
|
+
};
|
|
240
|
+
signatures.push(signatureDictionary);
|
|
241
|
+
} catch (error) {
|
|
242
|
+
if (error instanceof import_core_sdk.TransactionReviewError) {
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
throw new Error(
|
|
246
|
+
`ParaSolanaSigner: Failed to sign message ${i + 1}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return signatures;
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
modifyAndSignMessages(messages, config) {
|
|
254
|
+
return __async(this, null, function* () {
|
|
255
|
+
const signatureDictionaries = yield this.signMessages(messages, config);
|
|
256
|
+
return messages.map((message, index) => __spreadProps(__spreadValues({}, message), {
|
|
257
|
+
signatures: __spreadValues(__spreadValues({}, message.signatures), signatureDictionaries[index])
|
|
258
|
+
}));
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
263
|
+
0 && (module.exports = {
|
|
264
|
+
ParaSolanaSigner
|
|
265
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ParaSolanaSigner } from "./solanaSigner.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
|
+
import { ParaSolanaSigner as ParaSolanaSigner2 } from "./solanaSigner.js";
|
|
4
|
+
function createParaSolanaSigner(params) {
|
|
5
|
+
return new ParaSolanaSigner2(params);
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
ParaSolanaSigner,
|
|
9
|
+
createParaSolanaSigner
|
|
10
|
+
};
|
|
@@ -0,0 +1,234 @@
|
|
|
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 { TransactionReviewError } from "@getpara/core-sdk";
|
|
41
|
+
import { getBase64EncodedWireTransaction } from "@solana/transactions";
|
|
42
|
+
import { getAddressEncoder } from "@solana/addresses";
|
|
43
|
+
import bs58 from "bs58";
|
|
44
|
+
class ParaSolanaSigner {
|
|
45
|
+
constructor(params) {
|
|
46
|
+
var _a;
|
|
47
|
+
if (!params.para) {
|
|
48
|
+
throw new Error("ParaSolanaSigner: `para` parameter is required");
|
|
49
|
+
}
|
|
50
|
+
if (!params.rpc) {
|
|
51
|
+
throw new Error("ParaSolanaSigner: `rpc` parameter is required");
|
|
52
|
+
}
|
|
53
|
+
this.para = params.para;
|
|
54
|
+
this.rpc = params.rpc;
|
|
55
|
+
try {
|
|
56
|
+
this.walletId = params.para.findWalletId(params.walletId, { type: ["SOLANA"] });
|
|
57
|
+
} catch (error) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`ParaSolanaSigner: Failed to find Solana wallet. ${error instanceof Error ? error.message : "Unknown error"}`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (!((_a = params.para.wallets[this.walletId]) == null ? void 0 : _a.address)) {
|
|
63
|
+
throw new Error("ParaSolanaSigner: Wallet address not found");
|
|
64
|
+
}
|
|
65
|
+
this.address = params.para.wallets[this.walletId].address;
|
|
66
|
+
this.sender = new Uint8Array(getAddressEncoder().encode(this.address));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Sign one or more transactions
|
|
70
|
+
* @param transactions - Array of transactions to sign
|
|
71
|
+
* @param config - Optional configuration including abort signal
|
|
72
|
+
* @returns Array of signature dictionaries
|
|
73
|
+
*/
|
|
74
|
+
signTransactions(transactions, config) {
|
|
75
|
+
return __async(this, null, function* () {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
if (!transactions || transactions.length === 0) {
|
|
78
|
+
throw new Error("ParaSolanaSigner: No transactions provided to sign");
|
|
79
|
+
}
|
|
80
|
+
if ((_a = config == null ? void 0 : config.abortSignal) == null ? void 0 : _a.aborted) {
|
|
81
|
+
throw new Error("ParaSolanaSigner: Operation was aborted before starting");
|
|
82
|
+
}
|
|
83
|
+
const signatures = [];
|
|
84
|
+
for (let i = 0; i < transactions.length; i++) {
|
|
85
|
+
const transaction = transactions[i];
|
|
86
|
+
if ((_b = config == null ? void 0 : config.abortSignal) == null ? void 0 : _b.aborted) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`ParaSolanaSigner: Operation was aborted while signing transaction ${i + 1} of ${transactions.length}`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
if (!transaction.messageBytes || transaction.messageBytes.length === 0) {
|
|
92
|
+
throw new Error(`ParaSolanaSigner: Transaction ${i + 1} has no message bytes to sign`);
|
|
93
|
+
}
|
|
94
|
+
const messageBase64 = Buffer.from(transaction.messageBytes).toString("base64");
|
|
95
|
+
try {
|
|
96
|
+
const res = yield this.para.signMessage({
|
|
97
|
+
walletId: this.walletId,
|
|
98
|
+
messageBase64
|
|
99
|
+
});
|
|
100
|
+
if (res.transactionReviewUrl) {
|
|
101
|
+
throw new TransactionReviewError(res.transactionReviewUrl);
|
|
102
|
+
}
|
|
103
|
+
const signatureBytes = Buffer.from(res.signature, "base64");
|
|
104
|
+
const signatureDictionary = {
|
|
105
|
+
[this.address]: signatureBytes
|
|
106
|
+
};
|
|
107
|
+
signatures.push(signatureDictionary);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (error instanceof TransactionReviewError) {
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
throw new Error(
|
|
113
|
+
`ParaSolanaSigner: Failed to sign transaction ${i + 1}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return signatures;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
modifyAndSignTransactions(transactions, config) {
|
|
121
|
+
return __async(this, null, function* () {
|
|
122
|
+
const signatureDictionaries = yield this.signTransactions(transactions, config);
|
|
123
|
+
const signedTransactions = transactions.map((transaction, index) => {
|
|
124
|
+
const signatureDictionary = signatureDictionaries[index];
|
|
125
|
+
const existingSignatures = transaction.signatures || {};
|
|
126
|
+
return __spreadProps(__spreadValues({}, transaction), {
|
|
127
|
+
signatures: __spreadValues(__spreadValues({}, existingSignatures), signatureDictionary)
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
return signedTransactions;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Sign and send transactions to the network
|
|
135
|
+
* @param transactions - Array of transactions to sign and send
|
|
136
|
+
* @param config - Optional configuration including abort signal
|
|
137
|
+
* @returns Array of transaction signatures
|
|
138
|
+
* @throws Error if no RPC client is configured
|
|
139
|
+
*/
|
|
140
|
+
signAndSendTransactions(transactions, config) {
|
|
141
|
+
return __async(this, null, function* () {
|
|
142
|
+
var _a;
|
|
143
|
+
if (!transactions || transactions.length === 0) {
|
|
144
|
+
throw new Error("ParaSolanaSigner: No transactions provided to send");
|
|
145
|
+
}
|
|
146
|
+
const signedTransactions = yield this.modifyAndSignTransactions(transactions, config);
|
|
147
|
+
const sentSignatures = [];
|
|
148
|
+
for (let i = 0; i < signedTransactions.length; i++) {
|
|
149
|
+
const signedTransaction = signedTransactions[i];
|
|
150
|
+
if ((_a = config == null ? void 0 : config.abortSignal) == null ? void 0 : _a.aborted) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`ParaSolanaSigner: Operation was aborted while sending transaction ${i + 1} of ${signedTransactions.length}`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const serializedTransaction = getBase64EncodedWireTransaction(signedTransaction);
|
|
157
|
+
const signatureBase58 = yield this.rpc.sendTransaction(serializedTransaction, {
|
|
158
|
+
encoding: "base64",
|
|
159
|
+
skipPreflight: false,
|
|
160
|
+
preflightCommitment: "processed"
|
|
161
|
+
}).send({ abortSignal: config == null ? void 0 : config.abortSignal });
|
|
162
|
+
const signatureBytes = bs58.decode(signatureBase58);
|
|
163
|
+
sentSignatures.push(signatureBytes);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
`ParaSolanaSigner: Failed to send transaction ${i + 1}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return sentSignatures;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Sign one or more messages
|
|
175
|
+
* @param messages - Array of messages to sign
|
|
176
|
+
* @param config - Optional configuration including abort signal
|
|
177
|
+
* @returns Array of signature dictionaries
|
|
178
|
+
*/
|
|
179
|
+
signMessages(messages, config) {
|
|
180
|
+
return __async(this, null, function* () {
|
|
181
|
+
var _a, _b;
|
|
182
|
+
if (!messages || messages.length === 0) {
|
|
183
|
+
throw new Error("ParaSolanaSigner: No messages provided to sign");
|
|
184
|
+
}
|
|
185
|
+
if ((_a = config == null ? void 0 : config.abortSignal) == null ? void 0 : _a.aborted) {
|
|
186
|
+
throw new Error("ParaSolanaSigner: Operation was aborted before starting");
|
|
187
|
+
}
|
|
188
|
+
const signatures = [];
|
|
189
|
+
for (let i = 0; i < messages.length; i++) {
|
|
190
|
+
const message = messages[i];
|
|
191
|
+
if ((_b = config == null ? void 0 : config.abortSignal) == null ? void 0 : _b.aborted) {
|
|
192
|
+
throw new Error(`ParaSolanaSigner: Operation was aborted while signing message ${i + 1} of ${messages.length}`);
|
|
193
|
+
}
|
|
194
|
+
if (!message.content || message.content.length === 0) {
|
|
195
|
+
throw new Error(`ParaSolanaSigner: Message ${i + 1} has no content to sign`);
|
|
196
|
+
}
|
|
197
|
+
const messageBase64 = Buffer.from(message.content).toString("base64");
|
|
198
|
+
try {
|
|
199
|
+
const res = yield this.para.signMessage({
|
|
200
|
+
walletId: this.walletId,
|
|
201
|
+
messageBase64
|
|
202
|
+
});
|
|
203
|
+
if (res.transactionReviewUrl) {
|
|
204
|
+
throw new TransactionReviewError(res.transactionReviewUrl);
|
|
205
|
+
}
|
|
206
|
+
const signatureBytes = Buffer.from(res.signature, "base64");
|
|
207
|
+
const signatureDictionary = {
|
|
208
|
+
[this.address]: signatureBytes
|
|
209
|
+
};
|
|
210
|
+
signatures.push(signatureDictionary);
|
|
211
|
+
} catch (error) {
|
|
212
|
+
if (error instanceof TransactionReviewError) {
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
throw new Error(
|
|
216
|
+
`ParaSolanaSigner: Failed to sign message ${i + 1}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return signatures;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
modifyAndSignMessages(messages, config) {
|
|
224
|
+
return __async(this, null, function* () {
|
|
225
|
+
const signatureDictionaries = yield this.signMessages(messages, config);
|
|
226
|
+
return messages.map((message, index) => __spreadProps(__spreadValues({}, message), {
|
|
227
|
+
signatures: __spreadValues(__spreadValues({}, message.signatures), signatureDictionaries[index])
|
|
228
|
+
}));
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
export {
|
|
233
|
+
ParaSolanaSigner
|
|
234
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ParaSolanaSigner } from './solanaSigner.js';
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
import { ParaSolanaSigner } from './solanaSigner.js';
|
|
4
|
+
import type { ParaSignerParams } from './types.js';
|
|
5
|
+
export declare function createParaSolanaSigner(params: ParaSignerParams): ParaSolanaSigner;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { TransactionPartialSigner, TransactionModifyingSigner, TransactionSendingSigner, MessagePartialSigner, MessageModifyingSigner, SignatureDictionary, SignableMessage, TransactionPartialSignerConfig, TransactionModifyingSignerConfig, TransactionSendingSignerConfig, MessagePartialSignerConfig, MessageModifyingSignerConfig } from '@solana/signers';
|
|
2
|
+
import type { Address } from '@solana/addresses';
|
|
3
|
+
import type { Transaction } from '@solana/transactions';
|
|
4
|
+
import type { SignatureBytes } from '@solana/keys';
|
|
5
|
+
import type { ParaSignerParams } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Para Solana Signer implementation for Solana v2 signers specification
|
|
8
|
+
*
|
|
9
|
+
* This signer integrates Para SDK with Solana's new v2 signer interfaces.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { ParaSolanaSigner } from '@getpara/solana-signers-v2-integration';
|
|
14
|
+
* import { createRpc } from '@solana/rpc-spec';
|
|
15
|
+
* import { createSolanaRpcApi } from '@solana/rpc-api';
|
|
16
|
+
* import { createHttpTransport } from '@solana/rpc-transport-http';
|
|
17
|
+
*
|
|
18
|
+
* const transport = createHttpTransport({ url: 'https://api.devnet.solana.com' });
|
|
19
|
+
* const api = createSolanaRpcApi();
|
|
20
|
+
* const rpc = createRpc({ api, transport });
|
|
21
|
+
*
|
|
22
|
+
* const signer = new ParaSolanaSigner({
|
|
23
|
+
* para: paraClient,
|
|
24
|
+
* rpc
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Sign and send a transaction
|
|
28
|
+
* const signatures = await signer.signAndSendTransactions([transaction]);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class ParaSolanaSigner implements TransactionPartialSigner, TransactionModifyingSigner, TransactionSendingSigner, MessagePartialSigner, MessageModifyingSigner {
|
|
32
|
+
private para;
|
|
33
|
+
private walletId;
|
|
34
|
+
private rpc;
|
|
35
|
+
readonly address: Address;
|
|
36
|
+
readonly sender: Uint8Array;
|
|
37
|
+
constructor(params: ParaSignerParams);
|
|
38
|
+
/**
|
|
39
|
+
* Sign one or more transactions
|
|
40
|
+
* @param transactions - Array of transactions to sign
|
|
41
|
+
* @param config - Optional configuration including abort signal
|
|
42
|
+
* @returns Array of signature dictionaries
|
|
43
|
+
*/
|
|
44
|
+
signTransactions(transactions: readonly Transaction[], config?: TransactionPartialSignerConfig): Promise<readonly SignatureDictionary[]>;
|
|
45
|
+
modifyAndSignTransactions<T extends Transaction>(transactions: readonly T[], config?: TransactionModifyingSignerConfig): Promise<readonly T[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Sign and send transactions to the network
|
|
48
|
+
* @param transactions - Array of transactions to sign and send
|
|
49
|
+
* @param config - Optional configuration including abort signal
|
|
50
|
+
* @returns Array of transaction signatures
|
|
51
|
+
* @throws Error if no RPC client is configured
|
|
52
|
+
*/
|
|
53
|
+
signAndSendTransactions(transactions: readonly Transaction[], config?: TransactionSendingSignerConfig): Promise<readonly SignatureBytes[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Sign one or more messages
|
|
56
|
+
* @param messages - Array of messages to sign
|
|
57
|
+
* @param config - Optional configuration including abort signal
|
|
58
|
+
* @returns Array of signature dictionaries
|
|
59
|
+
*/
|
|
60
|
+
signMessages(messages: readonly SignableMessage[], config?: MessagePartialSignerConfig): Promise<readonly SignatureDictionary[]>;
|
|
61
|
+
modifyAndSignMessages(messages: readonly SignableMessage[], config?: MessageModifyingSignerConfig): Promise<readonly SignableMessage[]>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type ParaCore from '@getpara/core-sdk';
|
|
2
|
+
import type { Rpc } from '@solana/rpc-spec';
|
|
3
|
+
import type { SolanaRpcApi } from '@solana/rpc-api';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration parameters for creating a Para Solana Signer
|
|
6
|
+
*/
|
|
7
|
+
export interface ParaSignerParams {
|
|
8
|
+
/** Para client instance */
|
|
9
|
+
para: ParaCore;
|
|
10
|
+
/** Optional wallet ID. If not provided, will use the first Solana wallet */
|
|
11
|
+
walletId?: string;
|
|
12
|
+
/** RPC client instance for Solana network operations */
|
|
13
|
+
rpc: Rpc<SolanaRpcApi>;
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@getpara/solana-signers-v2-integration",
|
|
3
|
+
"version": "2.0.0-alpha.31",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@getpara/core-sdk": "2.0.0-alpha.31",
|
|
6
|
+
"bs58": "^6.0.0"
|
|
7
|
+
},
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@solana/addresses": "^2.2.1",
|
|
10
|
+
"@solana/keys": "^2.2.1",
|
|
11
|
+
"@solana/rpc-api": "^2.2.1",
|
|
12
|
+
"@solana/rpc-spec": "^2.2.1",
|
|
13
|
+
"@solana/signers": "^2.2.1",
|
|
14
|
+
"@solana/transactions": "^2.2.1",
|
|
15
|
+
"typescript": "^5.8.3"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/types/index.d.ts",
|
|
20
|
+
"import": "./dist/esm/index.js",
|
|
21
|
+
"require": "./dist/cjs/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"package.json"
|
|
27
|
+
],
|
|
28
|
+
"main": "dist/cjs/index.js",
|
|
29
|
+
"module": "dist/esm/index.js",
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@solana/addresses": "2.x",
|
|
32
|
+
"@solana/keys": "2.x",
|
|
33
|
+
"@solana/rpc-api": "2.x",
|
|
34
|
+
"@solana/rpc-spec": "2.x",
|
|
35
|
+
"@solana/signers": "2.x",
|
|
36
|
+
"@solana/transactions": "2.x"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
40
|
+
"build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration",
|
|
41
|
+
"test": "vitest run --coverage"
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"types": "dist/types/index.d.ts",
|
|
45
|
+
"typings": "dist/types/index.d.ts",
|
|
46
|
+
"gitHead": "54aac22b2d0b4cc730ab7f2e82cdd8a96729b039"
|
|
47
|
+
}
|