@getpara/stellar-sdk-v14-integration 2.20.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 +170 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/stellarSigner.js +108 -0
- package/dist/cjs/utils.js +83 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/stellarSigner.js +84 -0
- package/dist/esm/utils.js +49 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/stellarSigner.d.ts +19 -0
- package/dist/types/utils.d.ts +16 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# @getpara/stellar-sdk-v14-integration
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@getpara/stellar-sdk-v14-integration)
|
|
4
|
+
|
|
5
|
+
Para signer integration for the Stellar SDK v14. Sign Stellar transactions and Soroban auth entries using Para's MPC wallets.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @getpara/stellar-sdk-v14-integration @stellar/stellar-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start (Soroban Client)
|
|
14
|
+
|
|
15
|
+
`ParaStellarSigner` implements the Stellar SDK's `contract.Client` signer interface. Pass its methods directly to a Soroban client:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { ParaStellarSigner } from "@getpara/stellar-sdk-v14-integration";
|
|
19
|
+
import { contract, Networks } from "@stellar/stellar-sdk";
|
|
20
|
+
|
|
21
|
+
const signer = new ParaStellarSigner(para, Networks.TESTNET);
|
|
22
|
+
|
|
23
|
+
const client = new contract.Client({
|
|
24
|
+
contractId: "CABC...XYZ",
|
|
25
|
+
networkPassphrase: Networks.TESTNET,
|
|
26
|
+
rpcUrl: "https://soroban-testnet.stellar.org",
|
|
27
|
+
signTransaction: signer.signTransaction,
|
|
28
|
+
signAuthEntry: signer.signAuthEntry,
|
|
29
|
+
publicKey: signer.address,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const tx = await client.transfer({ from: signer.address, to: dest, amount: 100n });
|
|
33
|
+
const { result } = await tx.signAndSend();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Signing a Classic Transaction
|
|
37
|
+
|
|
38
|
+
Build a payment with `TransactionBuilder`, then sign the XDR with the signer:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { ParaStellarSigner } from "@getpara/stellar-sdk-v14-integration";
|
|
42
|
+
import {
|
|
43
|
+
Horizon,
|
|
44
|
+
Networks,
|
|
45
|
+
TransactionBuilder,
|
|
46
|
+
Operation,
|
|
47
|
+
Asset,
|
|
48
|
+
} from "@stellar/stellar-sdk";
|
|
49
|
+
|
|
50
|
+
const signer = new ParaStellarSigner(para, Networks.TESTNET);
|
|
51
|
+
|
|
52
|
+
const server = new Horizon.Server("https://horizon-testnet.stellar.org");
|
|
53
|
+
const account = await server.loadAccount(signer.address);
|
|
54
|
+
|
|
55
|
+
const tx = new TransactionBuilder(account, {
|
|
56
|
+
fee: "100",
|
|
57
|
+
networkPassphrase: Networks.TESTNET,
|
|
58
|
+
})
|
|
59
|
+
.addOperation(
|
|
60
|
+
Operation.payment({
|
|
61
|
+
destination: "GDEST...ABC",
|
|
62
|
+
asset: Asset.native(),
|
|
63
|
+
amount: "10",
|
|
64
|
+
})
|
|
65
|
+
)
|
|
66
|
+
.setTimeout(30)
|
|
67
|
+
.build();
|
|
68
|
+
|
|
69
|
+
const { signedTxXdr } = await signer.signTransaction(tx.toXDR());
|
|
70
|
+
await server.submitTransaction(
|
|
71
|
+
TransactionBuilder.fromXDR(signedTxXdr, Networks.TESTNET)
|
|
72
|
+
);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Factory Function
|
|
76
|
+
|
|
77
|
+
`createParaStellarSigner()` is a convenience wrapper that returns a `ParaStellarSigner` instance:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { createParaStellarSigner } from "@getpara/stellar-sdk-v14-integration";
|
|
81
|
+
import { Networks } from "@stellar/stellar-sdk";
|
|
82
|
+
|
|
83
|
+
const signer = createParaStellarSigner({
|
|
84
|
+
para,
|
|
85
|
+
networkPassphrase: Networks.TESTNET,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// signer.address — the Stellar G-address
|
|
89
|
+
// signer.signTransaction(xdr, opts?) — sign a transaction XDR
|
|
90
|
+
// signer.signAuthEntry(authEntry, opts?) — sign a Soroban auth entry
|
|
91
|
+
// signer.signTransactionXDR(xdr, networkPassphrase) — sign and return just the XDR string
|
|
92
|
+
// signer.signBytes(bytes) — sign arbitrary bytes
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## React Hook
|
|
96
|
+
|
|
97
|
+
`useStellarSigner()` from `@getpara/react-sdk` wraps `createParaStellarSigner()` in a React Query hook:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { useStellarSigner } from "@getpara/react-sdk";
|
|
101
|
+
import { Networks } from "@stellar/stellar-sdk";
|
|
102
|
+
|
|
103
|
+
function StellarSignButton() {
|
|
104
|
+
const { stellarSigner, isLoading } = useStellarSigner({
|
|
105
|
+
networkPassphrase: Networks.TESTNET,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const handleSign = async () => {
|
|
109
|
+
if (!stellarSigner) return;
|
|
110
|
+
const { signedTxXdr } = await stellarSigner.signTransaction(xdr);
|
|
111
|
+
console.log("Signed:", signedTxXdr);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
if (isLoading) return <p>Loading signer...</p>;
|
|
115
|
+
|
|
116
|
+
return <button onClick={handleSign}>Sign Transaction</button>;
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Utilities
|
|
121
|
+
|
|
122
|
+
### `deriveStellarAddress(solanaBase58Address: string): string`
|
|
123
|
+
|
|
124
|
+
Converts a Solana base58 public key to a Stellar G-address. Both use Ed25519, so the underlying key material is identical.
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { deriveStellarAddress } from "@getpara/stellar-sdk-v14-integration";
|
|
128
|
+
|
|
129
|
+
const stellarAddress = deriveStellarAddress(solanaPublicKey);
|
|
130
|
+
// => "GABC...XYZ"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### `createTestTransaction(para, walletId?, networkPassphrase?): Promise<Transaction>`
|
|
134
|
+
|
|
135
|
+
Builds a self-payment transaction for testing. Uses sequence number `"0"` — suitable for signature verification, not for broadcasting. For real transactions, load the account from Horizon first.
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { createTestTransaction } from "@getpara/stellar-sdk-v14-integration";
|
|
139
|
+
|
|
140
|
+
const tx = await createTestTransaction(para);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Network Configuration
|
|
144
|
+
|
|
145
|
+
The `networkPassphrase` parameter controls which Stellar network transactions are built for. Pass it at construction time and optionally override per-call:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
// Default to testnet
|
|
149
|
+
const signer = new ParaStellarSigner(para, Networks.TESTNET);
|
|
150
|
+
|
|
151
|
+
// Override for a specific call
|
|
152
|
+
const { signedTxXdr } = await signer.signTransaction(xdr, {
|
|
153
|
+
networkPassphrase: Networks.PUBLIC,
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Available passphrases from `@stellar/stellar-sdk`:
|
|
158
|
+
|
|
159
|
+
- `Networks.PUBLIC` — `"Public Global Stellar Network ; September 2015"`
|
|
160
|
+
- `Networks.TESTNET` — `"Test SDF Network ; September 2015"`
|
|
161
|
+
|
|
162
|
+
## Prerequisites
|
|
163
|
+
|
|
164
|
+
- A Para API key — get one at the [Developer Portal](https://developer.getpara.com)
|
|
165
|
+
- A Para wallet with a SOLANA wallet type (Stellar reuses SOLANA/Ed25519 keys)
|
|
166
|
+
|
|
167
|
+
## Learn More
|
|
168
|
+
|
|
169
|
+
- [Para Documentation](https://docs.getpara.com)
|
|
170
|
+
- [Stellar SDK v14 Docs](https://stellar.github.io/js-stellar-sdk/)
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
ParaStellarSigner: () => import_stellarSigner.ParaStellarSigner,
|
|
22
|
+
createParaStellarSigner: () => import_stellarSigner.createParaStellarSigner
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(src_exports);
|
|
25
|
+
var import_stellarSigner = require("./stellarSigner.js");
|
|
26
|
+
__reExport(src_exports, require("./utils.js"), module.exports);
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
ParaStellarSigner,
|
|
30
|
+
createParaStellarSigner,
|
|
31
|
+
...require("./utils.js")
|
|
32
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
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 stellarSigner_exports = {};
|
|
39
|
+
__export(stellarSigner_exports, {
|
|
40
|
+
ParaStellarSigner: () => ParaStellarSigner,
|
|
41
|
+
createParaStellarSigner: () => createParaStellarSigner
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(stellarSigner_exports);
|
|
44
|
+
var import_stellar_sdk = require("@stellar/stellar-sdk");
|
|
45
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
46
|
+
var import_utils = require("./utils.js");
|
|
47
|
+
class ParaStellarSigner {
|
|
48
|
+
constructor(para, networkPassphrase, walletId) {
|
|
49
|
+
this.signTransaction = (xdr, opts) => __async(this, null, function* () {
|
|
50
|
+
var _a;
|
|
51
|
+
const passphrase = (_a = opts == null ? void 0 : opts.networkPassphrase) != null ? _a : this.networkPassphrase;
|
|
52
|
+
if (!passphrase) {
|
|
53
|
+
throw new Error("networkPassphrase is required \u2014 provide it in the constructor or in opts");
|
|
54
|
+
}
|
|
55
|
+
const t = import_stellar_sdk.TransactionBuilder.fromXDR(xdr, passphrase);
|
|
56
|
+
const txHash = t.hash();
|
|
57
|
+
const signatureBuffer = yield this.signBytes(txHash);
|
|
58
|
+
t.addSignature(this.address, signatureBuffer.toString("base64"));
|
|
59
|
+
return { signedTxXdr: t.toXDR(), signerAddress: this.address };
|
|
60
|
+
});
|
|
61
|
+
this.signAuthEntry = (authEntry, _opts) => __async(this, null, function* () {
|
|
62
|
+
const entryHash = (0, import_stellar_sdk.hash)(Buffer.from(authEntry, "base64"));
|
|
63
|
+
const signatureBuffer = yield this.signBytes(entryHash);
|
|
64
|
+
return { signedAuthEntry: signatureBuffer.toString("base64"), signerAddress: this.address };
|
|
65
|
+
});
|
|
66
|
+
var _a;
|
|
67
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["STELLAR"] });
|
|
68
|
+
this.para = para;
|
|
69
|
+
this.networkPassphrase = networkPassphrase != null ? networkPassphrase : "";
|
|
70
|
+
const rawAddress = (_a = this.para.wallets[this.currentWalletId]) == null ? void 0 : _a.address;
|
|
71
|
+
if (!rawAddress) {
|
|
72
|
+
throw new Error("Stellar address not available. Ensure the wallet has a valid Ed25519 address.");
|
|
73
|
+
}
|
|
74
|
+
this.address = (0, import_utils.deriveStellarAddress)(rawAddress);
|
|
75
|
+
this.signTransaction = this.signTransaction.bind(this);
|
|
76
|
+
this.signAuthEntry = this.signAuthEntry.bind(this);
|
|
77
|
+
}
|
|
78
|
+
signBytes(bytes) {
|
|
79
|
+
return __async(this, null, function* () {
|
|
80
|
+
const res = yield this.para.signMessage({
|
|
81
|
+
walletId: this.currentWalletId,
|
|
82
|
+
messageBase64: bytes.toString("base64")
|
|
83
|
+
});
|
|
84
|
+
if (res.transactionReviewUrl) {
|
|
85
|
+
throw new import_core_sdk.TransactionReviewError(res.transactionReviewUrl);
|
|
86
|
+
}
|
|
87
|
+
return Buffer.from(res.signature, "base64");
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
signTransactionXDR(transactionXDR, networkPassphrase) {
|
|
91
|
+
return __async(this, null, function* () {
|
|
92
|
+
const { signedTxXdr } = yield this.signTransaction(transactionXDR, { networkPassphrase });
|
|
93
|
+
return signedTxXdr;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function createParaStellarSigner({
|
|
98
|
+
para,
|
|
99
|
+
networkPassphrase,
|
|
100
|
+
walletId
|
|
101
|
+
}) {
|
|
102
|
+
return new ParaStellarSigner(para, networkPassphrase, walletId);
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
ParaStellarSigner,
|
|
107
|
+
createParaStellarSigner
|
|
108
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
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 utils_exports = {};
|
|
49
|
+
__export(utils_exports, {
|
|
50
|
+
createTestTransaction: () => createTestTransaction,
|
|
51
|
+
deriveStellarAddress: () => deriveStellarAddress
|
|
52
|
+
});
|
|
53
|
+
module.exports = __toCommonJS(utils_exports);
|
|
54
|
+
var import_stellar_sdk = require("@stellar/stellar-sdk");
|
|
55
|
+
var import_bs58 = __toESM(require("bs58"));
|
|
56
|
+
function deriveStellarAddress(solanaBase58Address) {
|
|
57
|
+
const rawPubkey = import_bs58.default.decode(solanaBase58Address);
|
|
58
|
+
return import_stellar_sdk.StrKey.encodeEd25519PublicKey(Buffer.from(rawPubkey));
|
|
59
|
+
}
|
|
60
|
+
function createTestTransaction(_0, _1) {
|
|
61
|
+
return __async(this, arguments, function* (para, walletId, networkPassphrase = import_stellar_sdk.Networks.TESTNET) {
|
|
62
|
+
walletId = para.findWalletId(walletId, { type: ["STELLAR"] });
|
|
63
|
+
const wallet = para.wallets[walletId];
|
|
64
|
+
const solanaAddress = para.getDisplayAddress(wallet.id, { addressType: "SOLANA" });
|
|
65
|
+
const stellarAddress = deriveStellarAddress(solanaAddress);
|
|
66
|
+
const account = new import_stellar_sdk.Account(stellarAddress, "0");
|
|
67
|
+
return new import_stellar_sdk.TransactionBuilder(account, {
|
|
68
|
+
fee: "100",
|
|
69
|
+
networkPassphrase
|
|
70
|
+
}).addOperation(
|
|
71
|
+
import_stellar_sdk.Operation.payment({
|
|
72
|
+
destination: stellarAddress,
|
|
73
|
+
asset: import_stellar_sdk.Asset.native(),
|
|
74
|
+
amount: "0.01"
|
|
75
|
+
})
|
|
76
|
+
).setTimeout(30).build();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
createTestTransaction,
|
|
82
|
+
deriveStellarAddress
|
|
83
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
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 { TransactionBuilder, hash } from "@stellar/stellar-sdk";
|
|
22
|
+
import { TransactionReviewError } from "@getpara/core-sdk";
|
|
23
|
+
import { deriveStellarAddress } from "./utils.js";
|
|
24
|
+
class ParaStellarSigner {
|
|
25
|
+
constructor(para, networkPassphrase, walletId) {
|
|
26
|
+
this.signTransaction = (xdr, opts) => __async(this, null, function* () {
|
|
27
|
+
var _a;
|
|
28
|
+
const passphrase = (_a = opts == null ? void 0 : opts.networkPassphrase) != null ? _a : this.networkPassphrase;
|
|
29
|
+
if (!passphrase) {
|
|
30
|
+
throw new Error("networkPassphrase is required \u2014 provide it in the constructor or in opts");
|
|
31
|
+
}
|
|
32
|
+
const t = TransactionBuilder.fromXDR(xdr, passphrase);
|
|
33
|
+
const txHash = t.hash();
|
|
34
|
+
const signatureBuffer = yield this.signBytes(txHash);
|
|
35
|
+
t.addSignature(this.address, signatureBuffer.toString("base64"));
|
|
36
|
+
return { signedTxXdr: t.toXDR(), signerAddress: this.address };
|
|
37
|
+
});
|
|
38
|
+
this.signAuthEntry = (authEntry, _opts) => __async(this, null, function* () {
|
|
39
|
+
const entryHash = hash(Buffer.from(authEntry, "base64"));
|
|
40
|
+
const signatureBuffer = yield this.signBytes(entryHash);
|
|
41
|
+
return { signedAuthEntry: signatureBuffer.toString("base64"), signerAddress: this.address };
|
|
42
|
+
});
|
|
43
|
+
var _a;
|
|
44
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["STELLAR"] });
|
|
45
|
+
this.para = para;
|
|
46
|
+
this.networkPassphrase = networkPassphrase != null ? networkPassphrase : "";
|
|
47
|
+
const rawAddress = (_a = this.para.wallets[this.currentWalletId]) == null ? void 0 : _a.address;
|
|
48
|
+
if (!rawAddress) {
|
|
49
|
+
throw new Error("Stellar address not available. Ensure the wallet has a valid Ed25519 address.");
|
|
50
|
+
}
|
|
51
|
+
this.address = deriveStellarAddress(rawAddress);
|
|
52
|
+
this.signTransaction = this.signTransaction.bind(this);
|
|
53
|
+
this.signAuthEntry = this.signAuthEntry.bind(this);
|
|
54
|
+
}
|
|
55
|
+
signBytes(bytes) {
|
|
56
|
+
return __async(this, null, function* () {
|
|
57
|
+
const res = yield this.para.signMessage({
|
|
58
|
+
walletId: this.currentWalletId,
|
|
59
|
+
messageBase64: bytes.toString("base64")
|
|
60
|
+
});
|
|
61
|
+
if (res.transactionReviewUrl) {
|
|
62
|
+
throw new TransactionReviewError(res.transactionReviewUrl);
|
|
63
|
+
}
|
|
64
|
+
return Buffer.from(res.signature, "base64");
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
signTransactionXDR(transactionXDR, networkPassphrase) {
|
|
68
|
+
return __async(this, null, function* () {
|
|
69
|
+
const { signedTxXdr } = yield this.signTransaction(transactionXDR, { networkPassphrase });
|
|
70
|
+
return signedTxXdr;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function createParaStellarSigner({
|
|
75
|
+
para,
|
|
76
|
+
networkPassphrase,
|
|
77
|
+
walletId
|
|
78
|
+
}) {
|
|
79
|
+
return new ParaStellarSigner(para, networkPassphrase, walletId);
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
ParaStellarSigner,
|
|
83
|
+
createParaStellarSigner
|
|
84
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
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 { StrKey, Networks, TransactionBuilder, Operation, Asset, Account } from "@stellar/stellar-sdk";
|
|
22
|
+
import bs58 from "bs58";
|
|
23
|
+
function deriveStellarAddress(solanaBase58Address) {
|
|
24
|
+
const rawPubkey = bs58.decode(solanaBase58Address);
|
|
25
|
+
return StrKey.encodeEd25519PublicKey(Buffer.from(rawPubkey));
|
|
26
|
+
}
|
|
27
|
+
function createTestTransaction(_0, _1) {
|
|
28
|
+
return __async(this, arguments, function* (para, walletId, networkPassphrase = Networks.TESTNET) {
|
|
29
|
+
walletId = para.findWalletId(walletId, { type: ["STELLAR"] });
|
|
30
|
+
const wallet = para.wallets[walletId];
|
|
31
|
+
const solanaAddress = para.getDisplayAddress(wallet.id, { addressType: "SOLANA" });
|
|
32
|
+
const stellarAddress = deriveStellarAddress(solanaAddress);
|
|
33
|
+
const account = new Account(stellarAddress, "0");
|
|
34
|
+
return new TransactionBuilder(account, {
|
|
35
|
+
fee: "100",
|
|
36
|
+
networkPassphrase
|
|
37
|
+
}).addOperation(
|
|
38
|
+
Operation.payment({
|
|
39
|
+
destination: stellarAddress,
|
|
40
|
+
asset: Asset.native(),
|
|
41
|
+
amount: "0.01"
|
|
42
|
+
})
|
|
43
|
+
).setTimeout(30).build();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
createTestTransaction,
|
|
48
|
+
deriveStellarAddress
|
|
49
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { contract } from '@stellar/stellar-sdk';
|
|
2
|
+
import ParaCore from '@getpara/core-sdk';
|
|
3
|
+
export interface CreateParaStellarSignerOptions {
|
|
4
|
+
para: ParaCore;
|
|
5
|
+
networkPassphrase?: string;
|
|
6
|
+
walletId?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class ParaStellarSigner {
|
|
9
|
+
private para;
|
|
10
|
+
private currentWalletId;
|
|
11
|
+
private networkPassphrase;
|
|
12
|
+
address: string;
|
|
13
|
+
constructor(para: ParaCore, networkPassphrase?: string, walletId?: string);
|
|
14
|
+
signBytes(bytes: Buffer): Promise<Buffer>;
|
|
15
|
+
signTransaction: contract.SignTransaction;
|
|
16
|
+
signTransactionXDR(transactionXDR: string, networkPassphrase: string): Promise<string>;
|
|
17
|
+
signAuthEntry: contract.SignAuthEntry;
|
|
18
|
+
}
|
|
19
|
+
export declare function createParaStellarSigner({ para, networkPassphrase, walletId, }: CreateParaStellarSignerOptions): ParaStellarSigner;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TransactionBuilder } from '@stellar/stellar-sdk';
|
|
2
|
+
import ParaCore from '@getpara/core-sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Derives a Stellar StrKey address (G...) from a Solana base58 public key.
|
|
5
|
+
* Both use Ed25519, so the underlying key material is identical.
|
|
6
|
+
*/
|
|
7
|
+
export declare function deriveStellarAddress(solanaBase58Address: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Stellar Testnet test transaction to sign and validate that your Para application is properly working.
|
|
10
|
+
* The transaction, if broadcast, simply sends 0.01 XLM from the wallet back to itself.
|
|
11
|
+
* @param para your Para instance
|
|
12
|
+
* @param walletId the Solana wallet ID to use (Stellar reuses SOLANA wallet type)
|
|
13
|
+
* @param networkPassphrase the Stellar network passphrase (defaults to Testnet)
|
|
14
|
+
* @returns the generated unsigned Transaction
|
|
15
|
+
*/
|
|
16
|
+
export declare function createTestTransaction(para: ParaCore, walletId?: string, networkPassphrase?: string): Promise<ReturnType<TransactionBuilder['build']>>;
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@getpara/stellar-sdk-v14-integration",
|
|
3
|
+
"version": "2.20.0",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@getpara/core-sdk": "2.20.0",
|
|
6
|
+
"bs58": "^6.0.0"
|
|
7
|
+
},
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@stellar/stellar-sdk": "^14.0.0",
|
|
10
|
+
"typescript": "^5.8.3"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/types/index.d.ts",
|
|
15
|
+
"import": "./dist/esm/index.js",
|
|
16
|
+
"require": "./dist/cjs/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"package.json"
|
|
22
|
+
],
|
|
23
|
+
"main": "dist/cjs/index.js",
|
|
24
|
+
"module": "dist/esm/index.js",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@stellar/stellar-sdk": "^14.0.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
30
|
+
"test": "vitest run --coverage",
|
|
31
|
+
"build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
32
|
+
"build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
|
|
33
|
+
"build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration",
|
|
34
|
+
"old-build": "yarn build:cjs && yarn build:esm && yarn build:types"
|
|
35
|
+
},
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"types": "dist/types/index.d.ts",
|
|
38
|
+
"typings": "dist/types/index.d.ts",
|
|
39
|
+
"gitHead": "a8443bcc4018864f5e582f238ade1bb3b4e121f4"
|
|
40
|
+
}
|