@getpara/solana-web3.js-v1-integration 2.0.0-dev.0 → 2.0.0-dev.2
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 +5 -94
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/solana-web3js.js +108 -0
- package/dist/cjs/utils.js +74 -0
- package/dist/esm/index.js +2 -77
- package/dist/esm/package.json +4 -0
- package/dist/esm/solana-web3js.js +75 -0
- package/dist/esm/utils.js +59 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/solana-web3js.d.ts +0 -2
- package/dist/types/utils.d.ts +10 -0
- package/package.json +26 -23
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
package/dist/cjs/index.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
5
|
var __copyProps = (to, from, except, desc) => {
|
|
12
6
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
7
|
for (let key of __getOwnPropNames(from))
|
|
@@ -16,97 +10,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
10
|
}
|
|
17
11
|
return to;
|
|
18
12
|
};
|
|
19
|
-
var
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
27
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var __async = (__this, __arguments, generator) => {
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
var fulfilled = (value) => {
|
|
31
|
-
try {
|
|
32
|
-
step(generator.next(value));
|
|
33
|
-
} catch (e) {
|
|
34
|
-
reject(e);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var rejected = (value) => {
|
|
38
|
-
try {
|
|
39
|
-
step(generator.throw(value));
|
|
40
|
-
} catch (e) {
|
|
41
|
-
reject(e);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
45
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// src/index.ts
|
|
50
15
|
var src_exports = {};
|
|
51
|
-
__export(src_exports, {
|
|
52
|
-
ParaSolanaWeb3Signer: () => ParaSolanaWeb3Signer
|
|
53
|
-
});
|
|
54
16
|
module.exports = __toCommonJS(src_exports);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var solana = __toESM(require("@solana/web3.js"));
|
|
58
|
-
var import_bs58 = __toESM(require("bs58"));
|
|
59
|
-
var import_core_sdk = require("@getpara/core-sdk");
|
|
60
|
-
var ParaSolanaWeb3Signer = class {
|
|
61
|
-
constructor(para, connection, walletId) {
|
|
62
|
-
this.currentWalletId = para.findWalletId(walletId, { type: ["SOLANA"] });
|
|
63
|
-
this.connection = connection;
|
|
64
|
-
this.para = para;
|
|
65
|
-
this.address = para.wallets[this.currentWalletId].address;
|
|
66
|
-
this.sender = this.address ? new solana.PublicKey(import_bs58.default.decode(this.address)) : void 0;
|
|
67
|
-
}
|
|
68
|
-
signBytes(bytes) {
|
|
69
|
-
return __async(this, null, function* () {
|
|
70
|
-
const res = yield this.para.signMessage({ walletId: this.currentWalletId, messageBase64: bytes.toString("base64") });
|
|
71
|
-
if (res.transactionReviewUrl) {
|
|
72
|
-
throw new import_core_sdk.TransactionReviewError(res.transactionReviewUrl);
|
|
73
|
-
}
|
|
74
|
-
return Buffer.from(res.signature, "base64");
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
signTransaction(transaction) {
|
|
78
|
-
return __async(this, null, function* () {
|
|
79
|
-
if (transaction instanceof solana.VersionedTransaction) {
|
|
80
|
-
return yield this.signVersionedTransaction(transaction);
|
|
81
|
-
}
|
|
82
|
-
if (!transaction.recentBlockhash) {
|
|
83
|
-
transaction.recentBlockhash = (yield this.connection.getLatestBlockhash("finalized")).blockhash;
|
|
84
|
-
}
|
|
85
|
-
const bytesToSign = transaction.serializeMessage();
|
|
86
|
-
const sigBytes = yield this.signBytes(bytesToSign);
|
|
87
|
-
transaction.addSignature(this.sender, sigBytes);
|
|
88
|
-
return transaction;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
signVersionedTransaction(transaction) {
|
|
92
|
-
return __async(this, null, function* () {
|
|
93
|
-
if (!transaction.message.recentBlockhash) {
|
|
94
|
-
transaction.message.recentBlockhash = (yield this.connection.getLatestBlockhash("finalized")).blockhash;
|
|
95
|
-
}
|
|
96
|
-
const messageBytes = transaction.message.serialize();
|
|
97
|
-
const sigBytes = yield this.signBytes(Buffer.from(messageBytes));
|
|
98
|
-
transaction.addSignature(this.sender, sigBytes);
|
|
99
|
-
return transaction;
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
sendTransaction(transaction, options) {
|
|
103
|
-
return __async(this, null, function* () {
|
|
104
|
-
const signedTransaction = yield this.signTransaction(transaction);
|
|
105
|
-
return this.connection.sendRawTransaction(signedTransaction.serialize(), options);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
};
|
|
17
|
+
__reExport(src_exports, require("./solana-web3js.js"), module.exports);
|
|
18
|
+
__reExport(src_exports, require("./utils.js"), module.exports);
|
|
109
19
|
// Annotate the CommonJS export names for ESM import in node:
|
|
110
20
|
0 && (module.exports = {
|
|
111
|
-
|
|
21
|
+
...require("./solana-web3js.js"),
|
|
22
|
+
...require("./utils.js")
|
|
112
23
|
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var __async = (__this, __arguments, generator) => {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
var fulfilled = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.next(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var rejected = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.throw(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
45
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
var solana_web3js_exports = {};
|
|
49
|
+
__export(solana_web3js_exports, {
|
|
50
|
+
ParaSolanaWeb3Signer: () => ParaSolanaWeb3Signer
|
|
51
|
+
});
|
|
52
|
+
module.exports = __toCommonJS(solana_web3js_exports);
|
|
53
|
+
var solana = __toESM(require("@solana/web3.js"));
|
|
54
|
+
var import_bs58 = __toESM(require("bs58"));
|
|
55
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
56
|
+
class ParaSolanaWeb3Signer {
|
|
57
|
+
constructor(para, connection, walletId) {
|
|
58
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["SOLANA"] });
|
|
59
|
+
this.connection = connection;
|
|
60
|
+
this.para = para;
|
|
61
|
+
this.address = para.wallets[this.currentWalletId].address;
|
|
62
|
+
this.sender = this.address ? new solana.PublicKey(import_bs58.default.decode(this.address)) : void 0;
|
|
63
|
+
}
|
|
64
|
+
signBytes(bytes) {
|
|
65
|
+
return __async(this, null, function* () {
|
|
66
|
+
const res = yield this.para.signMessage({ walletId: this.currentWalletId, messageBase64: bytes.toString("base64") });
|
|
67
|
+
if (res.transactionReviewUrl) {
|
|
68
|
+
throw new import_core_sdk.TransactionReviewError(res.transactionReviewUrl);
|
|
69
|
+
}
|
|
70
|
+
return Buffer.from(res.signature, "base64");
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
signTransaction(transaction) {
|
|
74
|
+
return __async(this, null, function* () {
|
|
75
|
+
if (transaction instanceof solana.VersionedTransaction) {
|
|
76
|
+
return yield this.signVersionedTransaction(transaction);
|
|
77
|
+
}
|
|
78
|
+
if (!transaction.recentBlockhash) {
|
|
79
|
+
transaction.recentBlockhash = (yield this.connection.getLatestBlockhash("finalized")).blockhash;
|
|
80
|
+
}
|
|
81
|
+
const bytesToSign = transaction.serializeMessage();
|
|
82
|
+
const sigBytes = yield this.signBytes(bytesToSign);
|
|
83
|
+
transaction.addSignature(this.sender, sigBytes);
|
|
84
|
+
return transaction;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
signVersionedTransaction(transaction) {
|
|
88
|
+
return __async(this, null, function* () {
|
|
89
|
+
if (!transaction.message.recentBlockhash) {
|
|
90
|
+
transaction.message.recentBlockhash = (yield this.connection.getLatestBlockhash("finalized")).blockhash;
|
|
91
|
+
}
|
|
92
|
+
const messageBytes = transaction.message.serialize();
|
|
93
|
+
const sigBytes = yield this.signBytes(Buffer.from(messageBytes));
|
|
94
|
+
transaction.addSignature(this.sender, sigBytes);
|
|
95
|
+
return transaction;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
sendTransaction(transaction, options) {
|
|
99
|
+
return __async(this, null, function* () {
|
|
100
|
+
const signedTransaction = yield this.signTransaction(transaction);
|
|
101
|
+
return this.connection.sendRawTransaction(signedTransaction.serialize(), options);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
ParaSolanaWeb3Signer
|
|
108
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
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 utils_exports = {};
|
|
39
|
+
__export(utils_exports, {
|
|
40
|
+
createTestTransaction: () => createTestTransaction
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(utils_exports);
|
|
43
|
+
var import_web3 = require("@solana/web3.js");
|
|
44
|
+
function createTestTransaction(para, walletId) {
|
|
45
|
+
return __async(this, null, function* () {
|
|
46
|
+
walletId = para.findWalletId(walletId, { type: ["SOLANA"] });
|
|
47
|
+
const connection = new import_web3.Connection((0, import_web3.clusterApiUrl)("devnet"));
|
|
48
|
+
const wallet = para.wallets[walletId];
|
|
49
|
+
const address = para.getDisplayAddress(wallet.id, { addressType: "SOLANA" });
|
|
50
|
+
const mePublicKey = new import_web3.PublicKey(address);
|
|
51
|
+
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash("confirmed");
|
|
52
|
+
return new import_web3.Transaction({
|
|
53
|
+
feePayer: mePublicKey,
|
|
54
|
+
blockhash,
|
|
55
|
+
lastValidBlockHeight
|
|
56
|
+
}).add(
|
|
57
|
+
import_web3.ComputeBudgetProgram.setComputeUnitLimit({
|
|
58
|
+
units: 12e4
|
|
59
|
+
}),
|
|
60
|
+
import_web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
61
|
+
microLamports: 500
|
|
62
|
+
}),
|
|
63
|
+
import_web3.SystemProgram.transfer({
|
|
64
|
+
fromPubkey: mePublicKey,
|
|
65
|
+
toPubkey: mePublicKey,
|
|
66
|
+
lamports: 0.01 * import_web3.LAMPORTS_PER_SOL
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
createTestTransaction
|
|
74
|
+
});
|
package/dist/esm/index.js
CHANGED
|
@@ -1,77 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/solana-web3js.ts
|
|
23
|
-
import * as solana from "@solana/web3.js";
|
|
24
|
-
import bs58 from "bs58";
|
|
25
|
-
import { TransactionReviewError } from "@getpara/core-sdk";
|
|
26
|
-
var ParaSolanaWeb3Signer = class {
|
|
27
|
-
constructor(para, connection, walletId) {
|
|
28
|
-
this.currentWalletId = para.findWalletId(walletId, { type: ["SOLANA"] });
|
|
29
|
-
this.connection = connection;
|
|
30
|
-
this.para = para;
|
|
31
|
-
this.address = para.wallets[this.currentWalletId].address;
|
|
32
|
-
this.sender = this.address ? new solana.PublicKey(bs58.decode(this.address)) : void 0;
|
|
33
|
-
}
|
|
34
|
-
signBytes(bytes) {
|
|
35
|
-
return __async(this, null, function* () {
|
|
36
|
-
const res = yield this.para.signMessage({ walletId: this.currentWalletId, messageBase64: bytes.toString("base64") });
|
|
37
|
-
if (res.transactionReviewUrl) {
|
|
38
|
-
throw new TransactionReviewError(res.transactionReviewUrl);
|
|
39
|
-
}
|
|
40
|
-
return Buffer.from(res.signature, "base64");
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
signTransaction(transaction) {
|
|
44
|
-
return __async(this, null, function* () {
|
|
45
|
-
if (transaction instanceof solana.VersionedTransaction) {
|
|
46
|
-
return yield this.signVersionedTransaction(transaction);
|
|
47
|
-
}
|
|
48
|
-
if (!transaction.recentBlockhash) {
|
|
49
|
-
transaction.recentBlockhash = (yield this.connection.getLatestBlockhash("finalized")).blockhash;
|
|
50
|
-
}
|
|
51
|
-
const bytesToSign = transaction.serializeMessage();
|
|
52
|
-
const sigBytes = yield this.signBytes(bytesToSign);
|
|
53
|
-
transaction.addSignature(this.sender, sigBytes);
|
|
54
|
-
return transaction;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
signVersionedTransaction(transaction) {
|
|
58
|
-
return __async(this, null, function* () {
|
|
59
|
-
if (!transaction.message.recentBlockhash) {
|
|
60
|
-
transaction.message.recentBlockhash = (yield this.connection.getLatestBlockhash("finalized")).blockhash;
|
|
61
|
-
}
|
|
62
|
-
const messageBytes = transaction.message.serialize();
|
|
63
|
-
const sigBytes = yield this.signBytes(Buffer.from(messageBytes));
|
|
64
|
-
transaction.addSignature(this.sender, sigBytes);
|
|
65
|
-
return transaction;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
sendTransaction(transaction, options) {
|
|
69
|
-
return __async(this, null, function* () {
|
|
70
|
-
const signedTransaction = yield this.signTransaction(transaction);
|
|
71
|
-
return this.connection.sendRawTransaction(signedTransaction.serialize(), options);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
export {
|
|
76
|
-
ParaSolanaWeb3Signer
|
|
77
|
-
};
|
|
1
|
+
export * from "./solana-web3js.js";
|
|
2
|
+
export * from "./utils.js";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import * as solana from "@solana/web3.js";
|
|
22
|
+
import bs58 from "bs58";
|
|
23
|
+
import { TransactionReviewError } from "@getpara/core-sdk";
|
|
24
|
+
class ParaSolanaWeb3Signer {
|
|
25
|
+
constructor(para, connection, walletId) {
|
|
26
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["SOLANA"] });
|
|
27
|
+
this.connection = connection;
|
|
28
|
+
this.para = para;
|
|
29
|
+
this.address = para.wallets[this.currentWalletId].address;
|
|
30
|
+
this.sender = this.address ? new solana.PublicKey(bs58.decode(this.address)) : void 0;
|
|
31
|
+
}
|
|
32
|
+
signBytes(bytes) {
|
|
33
|
+
return __async(this, null, function* () {
|
|
34
|
+
const res = yield this.para.signMessage({ walletId: this.currentWalletId, messageBase64: bytes.toString("base64") });
|
|
35
|
+
if (res.transactionReviewUrl) {
|
|
36
|
+
throw new TransactionReviewError(res.transactionReviewUrl);
|
|
37
|
+
}
|
|
38
|
+
return Buffer.from(res.signature, "base64");
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
signTransaction(transaction) {
|
|
42
|
+
return __async(this, null, function* () {
|
|
43
|
+
if (transaction instanceof solana.VersionedTransaction) {
|
|
44
|
+
return yield this.signVersionedTransaction(transaction);
|
|
45
|
+
}
|
|
46
|
+
if (!transaction.recentBlockhash) {
|
|
47
|
+
transaction.recentBlockhash = (yield this.connection.getLatestBlockhash("finalized")).blockhash;
|
|
48
|
+
}
|
|
49
|
+
const bytesToSign = transaction.serializeMessage();
|
|
50
|
+
const sigBytes = yield this.signBytes(bytesToSign);
|
|
51
|
+
transaction.addSignature(this.sender, sigBytes);
|
|
52
|
+
return transaction;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
signVersionedTransaction(transaction) {
|
|
56
|
+
return __async(this, null, function* () {
|
|
57
|
+
if (!transaction.message.recentBlockhash) {
|
|
58
|
+
transaction.message.recentBlockhash = (yield this.connection.getLatestBlockhash("finalized")).blockhash;
|
|
59
|
+
}
|
|
60
|
+
const messageBytes = transaction.message.serialize();
|
|
61
|
+
const sigBytes = yield this.signBytes(Buffer.from(messageBytes));
|
|
62
|
+
transaction.addSignature(this.sender, sigBytes);
|
|
63
|
+
return transaction;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
sendTransaction(transaction, options) {
|
|
67
|
+
return __async(this, null, function* () {
|
|
68
|
+
const signedTransaction = yield this.signTransaction(transaction);
|
|
69
|
+
return this.connection.sendRawTransaction(signedTransaction.serialize(), options);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
ParaSolanaWeb3Signer
|
|
75
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import {
|
|
22
|
+
clusterApiUrl,
|
|
23
|
+
ComputeBudgetProgram,
|
|
24
|
+
Connection,
|
|
25
|
+
LAMPORTS_PER_SOL,
|
|
26
|
+
PublicKey,
|
|
27
|
+
SystemProgram,
|
|
28
|
+
Transaction
|
|
29
|
+
} from "@solana/web3.js";
|
|
30
|
+
function createTestTransaction(para, walletId) {
|
|
31
|
+
return __async(this, null, function* () {
|
|
32
|
+
walletId = para.findWalletId(walletId, { type: ["SOLANA"] });
|
|
33
|
+
const connection = new Connection(clusterApiUrl("devnet"));
|
|
34
|
+
const wallet = para.wallets[walletId];
|
|
35
|
+
const address = para.getDisplayAddress(wallet.id, { addressType: "SOLANA" });
|
|
36
|
+
const mePublicKey = new PublicKey(address);
|
|
37
|
+
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash("confirmed");
|
|
38
|
+
return new Transaction({
|
|
39
|
+
feePayer: mePublicKey,
|
|
40
|
+
blockhash,
|
|
41
|
+
lastValidBlockHeight
|
|
42
|
+
}).add(
|
|
43
|
+
ComputeBudgetProgram.setComputeUnitLimit({
|
|
44
|
+
units: 12e4
|
|
45
|
+
}),
|
|
46
|
+
ComputeBudgetProgram.setComputeUnitPrice({
|
|
47
|
+
microLamports: 500
|
|
48
|
+
}),
|
|
49
|
+
SystemProgram.transfer({
|
|
50
|
+
fromPubkey: mePublicKey,
|
|
51
|
+
toPubkey: mePublicKey,
|
|
52
|
+
lamports: 0.01 * LAMPORTS_PER_SOL
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
createTestTransaction
|
|
59
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import ParaCore from '@getpara/core-sdk';
|
|
2
|
+
import { Transaction } from '@solana/web3.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Solana Devnet test transaction to sign and validate that your Para application is properly working.
|
|
5
|
+
* The transaction, if broadcast, simply sends 0.01 SOL from the wallet back to itself.
|
|
6
|
+
* @param {ParaCore} para your Para instance
|
|
7
|
+
* @param {string} walletId the Solana wallet ID to use.
|
|
8
|
+
* @returns {Promise<Transaction>} the generated transaction.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTestTransaction(para: ParaCore, walletId?: string): Promise<Transaction>;
|
package/package.json
CHANGED
|
@@ -1,35 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/solana-web3.js-v1-integration",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
4
|
-
"main": "dist/cjs/index.js",
|
|
5
|
-
"module": "dist/esm/index.js",
|
|
6
|
-
"types": "dist/types/index.d.ts",
|
|
7
|
-
"typings": "dist/types/index.d.ts",
|
|
8
|
-
"sideEffects": false,
|
|
3
|
+
"version": "2.0.0-dev.2",
|
|
9
4
|
"dependencies": {
|
|
10
|
-
"@getpara/core-sdk": "2.0.0-dev.
|
|
11
|
-
"@solana/web3.js": "^1.95.8"
|
|
12
|
-
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
15
|
-
"old-build": "yarn build:cjs && yarn build:esm && yarn build:types",
|
|
16
|
-
"build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
17
|
-
"build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
|
|
18
|
-
"build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration"
|
|
5
|
+
"@getpara/core-sdk": "2.0.0-dev.2"
|
|
19
6
|
},
|
|
20
7
|
"devDependencies": {
|
|
21
|
-
"
|
|
8
|
+
"@solana/web3.js": "^1.98.0",
|
|
9
|
+
"typescript": "^5.8.3"
|
|
22
10
|
},
|
|
23
|
-
"files": [
|
|
24
|
-
"dist",
|
|
25
|
-
"package.json"
|
|
26
|
-
],
|
|
27
11
|
"exports": {
|
|
28
12
|
".": {
|
|
13
|
+
"types": "./dist/types/index.d.ts",
|
|
29
14
|
"import": "./dist/esm/index.js",
|
|
30
|
-
"require": "./dist/cjs/index.js"
|
|
31
|
-
"types": "./dist/types/index.d.ts"
|
|
15
|
+
"require": "./dist/cjs/index.js"
|
|
32
16
|
}
|
|
33
17
|
},
|
|
34
|
-
"
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"package.json"
|
|
21
|
+
],
|
|
22
|
+
"gitHead": "77d818539daa181c839a40f0ad5362af4058844e",
|
|
23
|
+
"main": "dist/cjs/index.js",
|
|
24
|
+
"module": "dist/esm/index.js",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@solana/web3.js": "1.x"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
30
|
+
"build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
31
|
+
"build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
|
|
32
|
+
"build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration",
|
|
33
|
+
"old-build": "yarn build:cjs && yarn build:esm && yarn build:types"
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"types": "dist/types/index.d.ts",
|
|
37
|
+
"typings": "dist/types/index.d.ts"
|
|
35
38
|
}
|
package/dist/cjs/index.js.br
DELETED
|
Binary file
|
package/dist/cjs/index.js.gz
DELETED
|
Binary file
|
package/dist/esm/index.js.br
DELETED
|
Binary file
|
package/dist/esm/index.js.gz
DELETED
|
Binary file
|