@getpara/solana-web3.js-v1-integration 1.7.1 → 1.8.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/dist/cjs/index.js +5 -94
- package/dist/cjs/solana-web3js.js +108 -0
- package/dist/cjs/utils.js +74 -0
- package/dist/esm/index.js +2 -15704
- 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/utils.d.ts +10 -0
- package/package.json +3 -3
- 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
|
@@ -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,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/solana-web3.js-v1-integration",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
7
7
|
"typings": "dist/types/index.d.ts",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@getpara/core-sdk": "1.
|
|
10
|
+
"@getpara/core-sdk": "1.8.0",
|
|
11
11
|
"@solana/web3.js": "^1.95.8"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"types": "./dist/types/index.d.ts"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "ef96e79558695ccbe148d25a8e3611c4596d1954"
|
|
35
35
|
}
|
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
|