@getpara/solana-web3.js-v1-integration 0.1.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.
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./solana-web3js.js"), exports);
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.ParaSolanaWeb3Signer = void 0;
39
+ const solana = __importStar(require("@solana/web3.js"));
40
+ const bs58_1 = __importDefault(require("bs58"));
41
+ const core_sdk_1 = require("@getpara/core-sdk");
42
+ class ParaSolanaWeb3Signer {
43
+ constructor(para, connection, walletId) {
44
+ this.currentWalletId = para.findWalletId(walletId, { type: ['SOLANA'] });
45
+ this.connection = connection;
46
+ this.para = para;
47
+ this.address = para.wallets[this.currentWalletId].address;
48
+ this.sender = this.address ? new solana.PublicKey(bs58_1.default.decode(this.address)) : undefined;
49
+ }
50
+ signBytes(bytes) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const res = yield this.para.signMessage({ walletId: this.currentWalletId, messageBase64: bytes.toString('base64') });
53
+ if (res.transactionReviewUrl) {
54
+ throw new core_sdk_1.TransactionReviewError(res.transactionReviewUrl);
55
+ }
56
+ return Buffer.from(res.signature, 'base64');
57
+ });
58
+ }
59
+ signTransaction(transaction) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ if (transaction instanceof solana.VersionedTransaction) {
62
+ return (yield this.signVersionedTransaction(transaction));
63
+ }
64
+ if (!transaction.recentBlockhash) {
65
+ transaction.recentBlockhash = (yield this.connection.getLatestBlockhash('finalized')).blockhash;
66
+ }
67
+ const bytesToSign = transaction.serializeMessage();
68
+ const sigBytes = yield this.signBytes(bytesToSign);
69
+ transaction.addSignature(this.sender, sigBytes);
70
+ return transaction;
71
+ });
72
+ }
73
+ signVersionedTransaction(transaction) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ if (!transaction.message.recentBlockhash) {
76
+ transaction.message.recentBlockhash = (yield this.connection.getLatestBlockhash('finalized')).blockhash;
77
+ }
78
+ const messageBytes = transaction.message.serialize();
79
+ const sigBytes = yield this.signBytes(Buffer.from(messageBytes));
80
+ transaction.addSignature(this.sender, sigBytes);
81
+ return transaction;
82
+ });
83
+ }
84
+ sendTransaction(transaction, options) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const signedTransaction = yield this.signTransaction(transaction);
87
+ return this.connection.sendRawTransaction(signedTransaction.serialize(), options);
88
+ });
89
+ }
90
+ }
91
+ exports.ParaSolanaWeb3Signer = ParaSolanaWeb3Signer;
@@ -0,0 +1 @@
1
+ export * from './solana-web3js.js';
@@ -0,0 +1 @@
1
+ {"type":"module","sideEffects":false}
@@ -0,0 +1,61 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as solana from '@solana/web3.js';
11
+ import bs58 from 'bs58';
12
+ import { TransactionReviewError } from '@getpara/core-sdk';
13
+ export class ParaSolanaWeb3Signer {
14
+ constructor(para, connection, walletId) {
15
+ this.currentWalletId = para.findWalletId(walletId, { type: ['SOLANA'] });
16
+ this.connection = connection;
17
+ this.para = para;
18
+ this.address = para.wallets[this.currentWalletId].address;
19
+ this.sender = this.address ? new solana.PublicKey(bs58.decode(this.address)) : undefined;
20
+ }
21
+ signBytes(bytes) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const res = yield this.para.signMessage({ walletId: this.currentWalletId, messageBase64: bytes.toString('base64') });
24
+ if (res.transactionReviewUrl) {
25
+ throw new TransactionReviewError(res.transactionReviewUrl);
26
+ }
27
+ return Buffer.from(res.signature, 'base64');
28
+ });
29
+ }
30
+ signTransaction(transaction) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ if (transaction instanceof solana.VersionedTransaction) {
33
+ return (yield this.signVersionedTransaction(transaction));
34
+ }
35
+ if (!transaction.recentBlockhash) {
36
+ transaction.recentBlockhash = (yield this.connection.getLatestBlockhash('finalized')).blockhash;
37
+ }
38
+ const bytesToSign = transaction.serializeMessage();
39
+ const sigBytes = yield this.signBytes(bytesToSign);
40
+ transaction.addSignature(this.sender, sigBytes);
41
+ return transaction;
42
+ });
43
+ }
44
+ signVersionedTransaction(transaction) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ if (!transaction.message.recentBlockhash) {
47
+ transaction.message.recentBlockhash = (yield this.connection.getLatestBlockhash('finalized')).blockhash;
48
+ }
49
+ const messageBytes = transaction.message.serialize();
50
+ const sigBytes = yield this.signBytes(Buffer.from(messageBytes));
51
+ transaction.addSignature(this.sender, sigBytes);
52
+ return transaction;
53
+ });
54
+ }
55
+ sendTransaction(transaction, options) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const signedTransaction = yield this.signTransaction(transaction);
58
+ return this.connection.sendRawTransaction(signedTransaction.serialize(), options);
59
+ });
60
+ }
61
+ }
@@ -0,0 +1 @@
1
+ export * from './solana-web3js.js';
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ import * as solana from '@solana/web3.js';
3
+ import ParaCore from '@getpara/core-sdk';
4
+ export declare class ParaSolanaWeb3Signer {
5
+ private connection;
6
+ private para;
7
+ private currentWalletId;
8
+ address?: string;
9
+ sender?: solana.PublicKey;
10
+ constructor(para: ParaCore, connection: solana.Connection, walletId?: string);
11
+ signBytes(bytes: Buffer): Promise<Buffer>;
12
+ signTransaction<T extends solana.Transaction | solana.VersionedTransaction>(transaction: T): Promise<T>;
13
+ signVersionedTransaction(transaction: solana.VersionedTransaction): Promise<solana.VersionedTransaction>;
14
+ sendTransaction(transaction: solana.Transaction | solana.VersionedTransaction, options?: solana.SendOptions): Promise<string>;
15
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@getpara/solana-web3.js-v1-integration",
3
+ "version": "0.1.0",
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,
9
+ "dependencies": {
10
+ "@getpara/core-sdk": "0.1.0",
11
+ "@solana/web3.js": "^1.95.8"
12
+ },
13
+ "scripts": {
14
+ "build": "yarn build:cjs && yarn build:esm && yarn build:types",
15
+ "build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
16
+ "build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
17
+ "build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration"
18
+ },
19
+ "devDependencies": {
20
+ "typescript": "5.1.6"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "package.json"
25
+ ],
26
+ "exports": {
27
+ ".": {
28
+ "import": "./dist/esm/index.js",
29
+ "require": "./dist/cjs/index.js",
30
+ "types": "./dist/types/index.d.ts"
31
+ }
32
+ },
33
+ "gitHead": "625aaa94001a5461dcde8d6775c3b73f3862c76c"
34
+ }