stellar-aa-sdk 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.
- package/LICENSE +21 -0
- package/README.md +214 -0
- package/dist/SmartWallet.d.ts +32 -0
- package/dist/SmartWallet.d.ts.map +1 -0
- package/dist/SmartWallet.js +168 -0
- package/dist/SmartWallet.js.map +1 -0
- package/dist/WalletFactory.d.ts +26 -0
- package/dist/WalletFactory.d.ts.map +1 -0
- package/dist/WalletFactory.js +114 -0
- package/dist/WalletFactory.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/soroban-utils.d.ts +27 -0
- package/dist/soroban-utils.d.ts.map +1 -0
- package/dist/soroban-utils.js +142 -0
- package/dist/soroban-utils.js.map +1 -0
- package/dist/types.d.ts +77 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# SDK for Stellar Account Abstraction Smart Wallet
|
|
2
|
+
|
|
3
|
+
This package provides the TypeScript SDK for interacting with the Stellar Account Abstraction (AA) Smart Wallet contract on Soroban. It simplifies the process of deploying new smart wallets, managing their ownership, setting up session keys, adding guardians, and facilitating recovery.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install the SDK using npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @stellar-aa/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
The SDK primarily exposes two main classes: `WalletFactory` for deploying new smart wallets and `SmartWallet` for interacting with existing deployed wallets.
|
|
16
|
+
|
|
17
|
+
### Account Funding Requirements
|
|
18
|
+
|
|
19
|
+
Before using the SDK, ensure the following accounts are funded:
|
|
20
|
+
|
|
21
|
+
1. **Source Account** - Required to pay for wallet deployment and owner operations
|
|
22
|
+
2. **Guardian Accounts** - Required if you plan to use the recovery feature (guardians must sign recovery transactions)
|
|
23
|
+
|
|
24
|
+
For testnet, you can use [Friendbot](https://friendbot.stellar.org) to fund accounts. See examples below.
|
|
25
|
+
|
|
26
|
+
### `WalletFactory`
|
|
27
|
+
|
|
28
|
+
Used to deploy new instances of the `SmartWallet` contract.
|
|
29
|
+
|
|
30
|
+
#### Constructor
|
|
31
|
+
|
|
32
|
+
`new WalletFactory(config: FactoryConfig)`
|
|
33
|
+
|
|
34
|
+
- `config`: An object containing:
|
|
35
|
+
- `wasmHash`: The WASM hash of the `smart-wallet` contract to deploy.
|
|
36
|
+
- **Testnet WASM Hash**: `8a02111e765f6fc970a95b9af8efc137649a611b2b576a52bfe5c59a0a1a5da0`
|
|
37
|
+
- **Mainnet WASM Hash**: `MAINNET_WASM_HASH_HERE` (Not available yet)
|
|
38
|
+
|
|
39
|
+
You can obtain the WASM hash after deploying your `smart-wallet` contract to a specific network (see [`contracts/smart-wallet/README.md`](../contracts/smart-wallet/README.md) for deployment instructions).
|
|
40
|
+
- `rpcUrl`: The URL of the Soroban RPC server.
|
|
41
|
+
- `networkPassphrase`: The network passphrase (e.g., `Networks.TESTNET`).
|
|
42
|
+
|
|
43
|
+
#### Methods
|
|
44
|
+
|
|
45
|
+
##### `createWallet(ownerPublicKey: string, sourceKeypair: StellarSDK.Keypair): Promise<string>`
|
|
46
|
+
|
|
47
|
+
Deploys a new `SmartWallet` contract and initializes it with the specified `ownerPublicKey`.
|
|
48
|
+
|
|
49
|
+
- `ownerPublicKey`: The public key of the account that will be the initial owner of the smart wallet.
|
|
50
|
+
- `sourceKeypair`: A `StellarSDK.Keypair` of an account that will pay for the deployment transaction and sign it. This account needs to be funded.
|
|
51
|
+
- Returns: A `Promise` that resolves to the `contractId` of the newly deployed smart wallet.
|
|
52
|
+
|
|
53
|
+
**Example:**
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { WalletFactory, StellarSDK } from '@stellar-aa/sdk';
|
|
57
|
+
|
|
58
|
+
const { Keypair, Networks } = StellarSDK;
|
|
59
|
+
|
|
60
|
+
const rpcUrl = "https://soroban-testnet.stellar.org";
|
|
61
|
+
const networkPassphrase = Networks.TESTNET;
|
|
62
|
+
const wasmHash = "8a02111e765f6fc970a95b9af8efc137649a611b2b576a52bfe5c59a0a1a5da0"; // Testnet WASM hash
|
|
63
|
+
|
|
64
|
+
// Helper to fund account via Friendbot (Testnet only)
|
|
65
|
+
async function fundAccount(publicKey: string) {
|
|
66
|
+
const response = await fetch(
|
|
67
|
+
`https://friendbot.stellar.org?addr=${encodeURIComponent(publicKey)}`
|
|
68
|
+
);
|
|
69
|
+
if (!response.ok) throw new Error("Failed to fund account");
|
|
70
|
+
await response.json();
|
|
71
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function deployNewWallet() {
|
|
75
|
+
const factory = new WalletFactory({ wasmHash, rpcUrl, networkPassphrase });
|
|
76
|
+
|
|
77
|
+
const ownerKeypair = Keypair.random();
|
|
78
|
+
const sourceKeypair = Keypair.random();
|
|
79
|
+
|
|
80
|
+
// Fund the source account (required to pay for deployment)
|
|
81
|
+
await fundAccount(sourceKeypair.publicKey());
|
|
82
|
+
|
|
83
|
+
console.log("Deploying wallet for owner:", ownerKeypair.publicKey());
|
|
84
|
+
const contractId = await factory.createWallet(ownerKeypair.publicKey(), sourceKeypair);
|
|
85
|
+
console.log("Deployed Smart Wallet with ID:", contractId);
|
|
86
|
+
|
|
87
|
+
return { contractId, ownerKeypair };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// deployNewWallet().catch(console.error);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### `SmartWallet`
|
|
94
|
+
|
|
95
|
+
Used to interact with an already deployed `SmartWallet` contract.
|
|
96
|
+
|
|
97
|
+
#### Constructor
|
|
98
|
+
|
|
99
|
+
`new SmartWallet(config: WalletConfig)`
|
|
100
|
+
|
|
101
|
+
- `config`: An object containing:
|
|
102
|
+
- `contractId`: The contract ID of the deployed `SmartWallet`.
|
|
103
|
+
- `rpcUrl`: The URL of the Soroban RPC server.
|
|
104
|
+
- `networkPassphrase`: The network passphrase.
|
|
105
|
+
|
|
106
|
+
#### Methods
|
|
107
|
+
|
|
108
|
+
##### Owner Operations
|
|
109
|
+
|
|
110
|
+
These operations require the `sourceKeypair` to be the current owner of the `SmartWallet`.
|
|
111
|
+
|
|
112
|
+
- `initialize(ownerPublicKey: string, sourceKeypair: StellarSDK.Keypair): Promise<GetTransactionResponse>`
|
|
113
|
+
Initializes the wallet. This should only be called once after deployment. `WalletFactory.createWallet` handles this automatically.
|
|
114
|
+
|
|
115
|
+
- `execute(targetContractId: string, functionName: string, args: unknown[], sourceKeypair: StellarSDK.Keypair): Promise<GetTransactionResponse>`
|
|
116
|
+
Allows the `SmartWallet` owner to execute an arbitrary function on another Soroban contract.
|
|
117
|
+
|
|
118
|
+
- `addGuardians(guardianAddresses: string[], sourceKeypair: StellarSDK.Keypair): Promise<GetTransactionResponse>`
|
|
119
|
+
Adds new public keys to the list of guardians for recovery.
|
|
120
|
+
|
|
121
|
+
##### Session Operations
|
|
122
|
+
|
|
123
|
+
- `createSession(sessionKeyPublicKey: string, limit: string, durationSeconds: number, sourceKeypair: StellarSDK.Keypair): Promise<GetTransactionResponse>`
|
|
124
|
+
Creates a new session key with a defined spending `limit` (in stroops) and `durationSeconds`. The `sourceKeypair` must be the owner.
|
|
125
|
+
|
|
126
|
+
- `executeSession(sessionKeyPublicKey: string, targetContractId: string, functionName: string, args: unknown[], amount: string, sourceKeypair: StellarSDK.Keypair): Promise<GetTransactionResponse>`
|
|
127
|
+
Executes a contract call using a session key. The `sourceKeypair` must be the session keypair. The `amount` represents the value being spent against the session's limit.
|
|
128
|
+
|
|
129
|
+
##### Recovery Operations
|
|
130
|
+
|
|
131
|
+
- `recover(newOwnerPublicKey: string, guardian1PublicKey: string, guardian2PublicKey: string, guardian1Keypair: StellarSDK.Keypair, guardian2Keypair: StellarSDK.Keypair): Promise<GetTransactionResponse>`
|
|
132
|
+
Recovers the wallet by setting a `newOwnerPublicKey`. This requires two guardians to sign the transaction. The method uses Soroban's authorization framework with `authorizeEntry` to properly sign multi-party auth requirements.
|
|
133
|
+
|
|
134
|
+
##### View Functions (Read-only)
|
|
135
|
+
|
|
136
|
+
These methods perform simulations and do not require transaction signing.
|
|
137
|
+
|
|
138
|
+
- `getOwner(): Promise<string>`
|
|
139
|
+
Returns the public key of the current owner of the `SmartWallet`.
|
|
140
|
+
|
|
141
|
+
- `getGuardians(): Promise<string[]>`
|
|
142
|
+
Returns an array of public keys of the registered guardians.
|
|
143
|
+
|
|
144
|
+
- `getSession(sessionKeyPublicKey: string): Promise<Session | null>`
|
|
145
|
+
Returns the details of a specific session key, or `null` if not found.
|
|
146
|
+
|
|
147
|
+
### Example Usage (Continued from Factory Deployment)
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { SmartWallet, StellarSDK } from '@stellar-aa/sdk';
|
|
151
|
+
|
|
152
|
+
// Assuming contractId and ownerKeypair are obtained from WalletFactory.createWallet()
|
|
153
|
+
const { contractId, ownerKeypair } = await deployNewWallet(); // Call the example from above
|
|
154
|
+
|
|
155
|
+
const rpcUrl = "https://soroban-testnet.stellar.org";
|
|
156
|
+
const networkPassphrase = StellarSDK.Networks.TESTNET;
|
|
157
|
+
|
|
158
|
+
async function interactWithWallet(contractId: string, ownerKeypair: StellarSDK.Keypair) {
|
|
159
|
+
const smartWallet = new SmartWallet({ contractId, rpcUrl, networkPassphrase });
|
|
160
|
+
|
|
161
|
+
console.log("\n--- Interacting with Smart Wallet ---");
|
|
162
|
+
|
|
163
|
+
// Get Owner
|
|
164
|
+
const owner = await smartWallet.getOwner();
|
|
165
|
+
console.log("Current Owner:", owner);
|
|
166
|
+
|
|
167
|
+
// Add Guardians
|
|
168
|
+
// NOTE: Guardian accounts must be funded before they can sign recovery transactions
|
|
169
|
+
const guardian1Keypair = StellarSDK.Keypair.random();
|
|
170
|
+
const guardian2Keypair = StellarSDK.Keypair.random();
|
|
171
|
+
|
|
172
|
+
// Fund guardians (required for recovery)
|
|
173
|
+
await fundAccount(guardian1Keypair.publicKey());
|
|
174
|
+
await fundAccount(guardian2Keypair.publicKey());
|
|
175
|
+
|
|
176
|
+
await smartWallet.addGuardians(
|
|
177
|
+
[guardian1Keypair.publicKey(), guardian2Keypair.publicKey()],
|
|
178
|
+
ownerKeypair
|
|
179
|
+
);
|
|
180
|
+
console.log("Guardians added:", await smartWallet.getGuardians());
|
|
181
|
+
|
|
182
|
+
// Create Session
|
|
183
|
+
const sessionKeypair = StellarSDK.Keypair.random();
|
|
184
|
+
await smartWallet.createSession(
|
|
185
|
+
sessionKeypair.publicKey(),
|
|
186
|
+
"5000000", // 5 XLM limit
|
|
187
|
+
3600, // 1 hour duration
|
|
188
|
+
ownerKeypair
|
|
189
|
+
);
|
|
190
|
+
console.log("Session created for:", sessionKeypair.publicKey());
|
|
191
|
+
console.log("Session info:", await smartWallet.getSession(sessionKeypair.publicKey()));
|
|
192
|
+
|
|
193
|
+
// Recover Wallet
|
|
194
|
+
const newOwnerKeypair = StellarSDK.Keypair.random();
|
|
195
|
+
console.log("Initiating recovery with new owner:", newOwnerKeypair.publicKey());
|
|
196
|
+
await smartWallet.recover(
|
|
197
|
+
newOwnerKeypair.publicKey(),
|
|
198
|
+
guardian1Keypair.publicKey(),
|
|
199
|
+
guardian2Keypair.publicKey(),
|
|
200
|
+
guardian1Keypair,
|
|
201
|
+
guardian2Keypair
|
|
202
|
+
);
|
|
203
|
+
console.log("Wallet recovered. New owner is:", await smartWallet.getOwner());
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// interactWithWallet(contractId, ownerKeypair).catch(console.error);
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Types and Utilities
|
|
210
|
+
|
|
211
|
+
The SDK also re-exports `StellarSDK` for convenience and provides utility functions from `soroban-utils.ts` for common Soroban transaction patterns, although these are mostly used internally by `SmartWallet` and `WalletFactory`. Key types like `Session`, `WalletConfig`, and `FactoryConfig` are also exported.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
**Note**: For a complete working example, refer to the [`sdk-test/test.ts`](../sdk-test/test.ts) file, which demonstrates the full lifecycle and interaction patterns.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as StellarSDK from "@stellar/stellar-sdk";
|
|
2
|
+
import { Session, WalletConfig, GetTransactionResponse } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* SmartWallet - Account abstraction for Stellar
|
|
5
|
+
*/
|
|
6
|
+
export declare class SmartWallet {
|
|
7
|
+
private contract;
|
|
8
|
+
private server;
|
|
9
|
+
private networkPassphrase;
|
|
10
|
+
constructor(config: WalletConfig);
|
|
11
|
+
/** Build and submit a contract call transaction */
|
|
12
|
+
private callContract;
|
|
13
|
+
/** Convert unknown args to ScVal */
|
|
14
|
+
private toScArgs;
|
|
15
|
+
/** Sign auth entries for multi-signer transactions */
|
|
16
|
+
private signAuthEntries;
|
|
17
|
+
/** Initialize wallet with owner */
|
|
18
|
+
initialize(ownerPublicKey: string, sourceKeypair: StellarSDK.Keypair): Promise<GetTransactionResponse>;
|
|
19
|
+
/** Execute contract call (owner only) */
|
|
20
|
+
execute(targetContractId: string, functionName: string, args: unknown[], sourceKeypair: StellarSDK.Keypair): Promise<GetTransactionResponse>;
|
|
21
|
+
/** Add guardians (owner only) */
|
|
22
|
+
addGuardians(guardianAddresses: string[], sourceKeypair: StellarSDK.Keypair): Promise<GetTransactionResponse>;
|
|
23
|
+
/** Create session key (owner only) */
|
|
24
|
+
createSession(sessionKeyPublicKey: string, limit: string, durationSeconds: number, sourceKeypair: StellarSDK.Keypair): Promise<GetTransactionResponse>;
|
|
25
|
+
/** Execute using session key */
|
|
26
|
+
executeSession(sessionKeyPublicKey: string, targetContractId: string, functionName: string, args: unknown[], amount: string, sourceKeypair: StellarSDK.Keypair): Promise<GetTransactionResponse>;
|
|
27
|
+
recover(newOwnerPublicKey: string, guardian1PublicKey: string, guardian2PublicKey: string, guardian1Keypair: StellarSDK.Keypair, guardian2Keypair: StellarSDK.Keypair): Promise<GetTransactionResponse>;
|
|
28
|
+
getOwner(): Promise<string>;
|
|
29
|
+
getGuardians(): Promise<string[]>;
|
|
30
|
+
getSession(sessionKeyPublicKey: string): Promise<Session | null>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=SmartW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kB,EAAE,MAAM,EAC1B,gBAAgB,EAAE,UAAU,CAAC,OAAO,EACpC,gBAAgB,EAAE,UAAU,CAAC,OAAO,GACnC,OAAO,CAAC,sBAAsB,CAAC;IAwD5B,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAS3B,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IASjC,UAAU,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;CASvE"}
|
|
@@ -0,0 +1,168 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SmartWallet = void 0;
|
|
37
|
+
const StellarSDK = __importStar(require("@stellar/stellar-sdk"));
|
|
38
|
+
const types_1 = require("./types");
|
|
39
|
+
const soroban_utils_1 = require("./soroban-utils");
|
|
40
|
+
const { Contract, TransactionBuilder, BASE_FEE, Address, nativeToScVal } = StellarSDK;
|
|
41
|
+
// Cache the SDK type cast
|
|
42
|
+
const stellarWithRpc = StellarSDK;
|
|
43
|
+
/**
|
|
44
|
+
* SmartWallet - Account abstraction for Stellar
|
|
45
|
+
*/
|
|
46
|
+
class SmartWallet {
|
|
47
|
+
constructor(config) {
|
|
48
|
+
this.contract = new Contract(config.contractId);
|
|
49
|
+
const rpc = stellarWithRpc.rpc;
|
|
50
|
+
if (!rpc?.Server)
|
|
51
|
+
throw new Error("SorobanRpc.Server not found in SDK");
|
|
52
|
+
this.server = new rpc.Server(config.rpcUrl);
|
|
53
|
+
this.networkPassphrase = config.networkPassphrase;
|
|
54
|
+
}
|
|
55
|
+
/* Private helpers */
|
|
56
|
+
/** Build and submit a contract call transaction */
|
|
57
|
+
async callContract(method, args, sourceKeypair) {
|
|
58
|
+
const sourceAccount = await this.server.getAccount(sourceKeypair.publicKey());
|
|
59
|
+
const tx = new TransactionBuilder(sourceAccount, {
|
|
60
|
+
fee: BASE_FEE,
|
|
61
|
+
networkPassphrase: this.networkPassphrase,
|
|
62
|
+
})
|
|
63
|
+
.addOperation(this.contract.call(method, ...args))
|
|
64
|
+
.setTimeout(30)
|
|
65
|
+
.build();
|
|
66
|
+
return (0, soroban_utils_1.submitTransaction)(tx, sourceKeypair, this.server);
|
|
67
|
+
}
|
|
68
|
+
/** Convert unknown args to ScVal */
|
|
69
|
+
toScArgs(args) {
|
|
70
|
+
return args.map((arg) => typeof arg === "string" ? nativeToScVal(arg) : arg);
|
|
71
|
+
}
|
|
72
|
+
/** Sign auth entries for multi-signer transactions */
|
|
73
|
+
async signAuthEntries(authEntries, signers, ledger) {
|
|
74
|
+
return Promise.all(authEntries.map(async (entry) => {
|
|
75
|
+
const creds = entry.credentials();
|
|
76
|
+
if (creds.switch().name !== "sorobanCredentialsAddress")
|
|
77
|
+
return entry;
|
|
78
|
+
const pubKey = StellarSDK.Address.fromScAddress(creds.address().address()).toString();
|
|
79
|
+
const signer = signers[pubKey];
|
|
80
|
+
if (!signer)
|
|
81
|
+
return entry;
|
|
82
|
+
return StellarSDK.authorizeEntry(entry, signer, ledger + 100, this.networkPassphrase);
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
/* Owner Operations */
|
|
86
|
+
/** Initialize wallet with owner */
|
|
87
|
+
async initialize(ownerPublicKey, sourceKeypair) {
|
|
88
|
+
return this.callContract(types_1.ContractMethod.Initialize, [new Address(ownerPublicKey).toScVal()], sourceKeypair);
|
|
89
|
+
}
|
|
90
|
+
/** Execute contract call (owner only) */
|
|
91
|
+
async execute(targetContractId, functionName, args, sourceKeypair) {
|
|
92
|
+
return this.callContract(types_1.ContractMethod.Execute, [
|
|
93
|
+
new Address(targetContractId).toScVal(),
|
|
94
|
+
nativeToScVal(functionName, { type: "symbol" }),
|
|
95
|
+
nativeToScVal(this.toScArgs(args), { type: "vec" }),
|
|
96
|
+
], sourceKeypair);
|
|
97
|
+
}
|
|
98
|
+
/** Add guardians (owner only) */
|
|
99
|
+
async addGuardians(guardianAddresses, sourceKeypair) {
|
|
100
|
+
const addresses = guardianAddresses.map((addr) => new Address(addr).toScVal());
|
|
101
|
+
return this.callContract(types_1.ContractMethod.AddGuardians, [nativeToScVal(addresses, { type: "vec" })], sourceKeypair);
|
|
102
|
+
}
|
|
103
|
+
/* Session operations */
|
|
104
|
+
/** Create session key (owner only) */
|
|
105
|
+
async createSession(sessionKeyPublicKey, limit, durationSeconds, sourceKeypair) {
|
|
106
|
+
return this.callContract(types_1.ContractMethod.CreateSession, [
|
|
107
|
+
new Address(sessionKeyPublicKey).toScVal(),
|
|
108
|
+
nativeToScVal(BigInt(limit), { type: "i128" }),
|
|
109
|
+
nativeToScVal(durationSeconds, { type: "u64" }),
|
|
110
|
+
], sourceKeypair);
|
|
111
|
+
}
|
|
112
|
+
/** Execute using session key */
|
|
113
|
+
async executeSession(sessionKeyPublicKey, targetContractId, functionName, args, amount, sourceKeypair) {
|
|
114
|
+
return this.callContract(types_1.ContractMethod.ExecuteSession, [
|
|
115
|
+
new Address(sessionKeyPublicKey).toScVal(),
|
|
116
|
+
new Address(targetContractId).toScVal(),
|
|
117
|
+
nativeToScVal(functionName, { type: "symbol" }),
|
|
118
|
+
nativeToScVal(this.toScArgs(args), { type: "vec" }),
|
|
119
|
+
nativeToScVal(BigInt(amount), { type: "i128" }),
|
|
120
|
+
], sourceKeypair);
|
|
121
|
+
}
|
|
122
|
+
/* Recovery (requires 2 guardian signatures) */
|
|
123
|
+
async recover(newOwnerPublicKey, guardian1PublicKey, guardian2PublicKey, guardian1Keypair, guardian2Keypair) {
|
|
124
|
+
const sourceAccount = await this.server.getAccount(guardian1Keypair.publicKey());
|
|
125
|
+
// Build transaction
|
|
126
|
+
const tx = new TransactionBuilder(sourceAccount, {
|
|
127
|
+
fee: BASE_FEE,
|
|
128
|
+
networkPassphrase: this.networkPassphrase,
|
|
129
|
+
})
|
|
130
|
+
.addOperation(this.contract.call(types_1.ContractMethod.Recover, new Address(newOwnerPublicKey).toScVal(), new Address(guardian1PublicKey).toScVal(), new Address(guardian2PublicKey).toScVal()))
|
|
131
|
+
.setTimeout(30)
|
|
132
|
+
.build();
|
|
133
|
+
// Simulate and validate
|
|
134
|
+
const sim = await this.server.simulateTransaction(tx);
|
|
135
|
+
if (!stellarWithRpc.rpc.Api.isSimulationSuccess(sim)) {
|
|
136
|
+
throw new Error(`Simulation failed: ${JSON.stringify(sim)}`);
|
|
137
|
+
}
|
|
138
|
+
const simAny = sim;
|
|
139
|
+
const authEntries = simAny.result?.auth || [];
|
|
140
|
+
if (!authEntries.length)
|
|
141
|
+
throw new Error("No auth entries in simulation");
|
|
142
|
+
// Sign auth entries with both guardians
|
|
143
|
+
const signedAuth = await this.signAuthEntries(authEntries, {
|
|
144
|
+
[guardian1PublicKey]: guardian1Keypair,
|
|
145
|
+
[guardian2PublicKey]: guardian2Keypair,
|
|
146
|
+
}, simAny.latestLedger || 0);
|
|
147
|
+
// Assemble with signed auth and submit
|
|
148
|
+
const modifiedSim = {
|
|
149
|
+
...simAny,
|
|
150
|
+
result: { ...simAny.result, auth: signedAuth },
|
|
151
|
+
};
|
|
152
|
+
const assembled = stellarWithRpc.rpc.assembleTransaction(tx, modifiedSim).build();
|
|
153
|
+
assembled.sign(guardian1Keypair);
|
|
154
|
+
return (0, soroban_utils_1.submitSignedTransaction)(assembled, this.server);
|
|
155
|
+
}
|
|
156
|
+
/* View functions (read-only) */
|
|
157
|
+
async getOwner() {
|
|
158
|
+
return (0, soroban_utils_1.executeSimulation)(this.contract, this.server, this.networkPassphrase, types_1.ContractMethod.GetOwner);
|
|
159
|
+
}
|
|
160
|
+
async getGuardians() {
|
|
161
|
+
return (0, soroban_utils_1.executeSimulation)(this.contract, this.server, this.networkPassphrase, types_1.ContractMethod.GetGuardians);
|
|
162
|
+
}
|
|
163
|
+
async getSession(sessionKeyPublicKey) {
|
|
164
|
+
return (0, soroban_utils_1.executeSimulation)(this.contract, this.server, this.networkPassphrase, types_1.ContractMethod.GetSession, new Address(sessionKeyPublicKey).toScVal());
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.SmartWallet = SmartWallet;
|
|
168
|
+
//# sourceMappingURL=SmartWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SmartWallet.js","sourceRoot":"","sources":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AAc,CAAC,QAAQ,CACxB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO,IAAA,iCAAiB,EACtB,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,iBAAiB,EACtB,sBAAc,CAAC,YAAY,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,mBAA2B;QAC1C,OAAO,IAAA,iCAAiB,EACtB,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,iBAAiB,EACtB,sBAAc,CAAC,UAAU,EACzB,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC,OAAO,EAAW,CACpD,CAAC;IACJ,CAAC;CACF;AAtPD,kCAsPC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as StellarSDK from '@stellar/stellar-sdk';
|
|
2
|
+
import { FactoryConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Factory for creating new SmartWallet instances
|
|
5
|
+
* - Deploys a new contract instance for each user from the pre-deployed WASM
|
|
6
|
+
*/
|
|
7
|
+
export declare class WalletFactory {
|
|
8
|
+
private wasmHash;
|
|
9
|
+
private server;
|
|
10
|
+
private networkPassphrase;
|
|
11
|
+
private rpcUrl;
|
|
12
|
+
constructor(config: FactoryConfig);
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new SmartWallet instance for a user
|
|
15
|
+
* @param ownerPublicKey - The public key that will own this wallet
|
|
16
|
+
* @param sourceKeypair - Keypair to pay for deployment and sign transactions
|
|
17
|
+
* @returns The contract ID of the newly deployed wallet
|
|
18
|
+
*/
|
|
19
|
+
createWallet(ownerPublicKey: string, sourceKeypair: StellarSDK.Keypair): Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Deploy a new contract instance from the WASM hash
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
private deployInstance;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=WalletFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WalletFactory.d.ts","sourceRoot":"","sources":["../src/WalletFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAGL,aAAa,EACd,MAAM,SAAS,CAAC;AAQjB;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,aAAa;IAcjC;;;;;OAKG;IACG,YAAY,CAChB,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,UAAU,CAAC,OAAO,GAChC,OAAO,CAAC,MAAM,CAAC;IAgBlB;;;OAGG;YACW,cAAc;CA6C7B"}
|
|
@@ -0,0 +1,114 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.WalletFactory = void 0;
|
|
37
|
+
const StellarSDK = __importStar(require("@stellar/stellar-sdk"));
|
|
38
|
+
const SmartWallet_1 = require("./SmartWallet");
|
|
39
|
+
const soroban_utils_1 = require("./soroban-utils");
|
|
40
|
+
const { TransactionBuilder, Operation, } = StellarSDK;
|
|
41
|
+
/**
|
|
42
|
+
* Factory for creating new SmartWallet instances
|
|
43
|
+
* - Deploys a new contract instance for each user from the pre-deployed WASM
|
|
44
|
+
*/
|
|
45
|
+
class WalletFactory {
|
|
46
|
+
constructor(config) {
|
|
47
|
+
this.wasmHash = config.wasmHash;
|
|
48
|
+
this.rpcUrl = config.rpcUrl;
|
|
49
|
+
this.networkPassphrase = config.networkPassphrase;
|
|
50
|
+
// Access the RPC server
|
|
51
|
+
const stellarWithRpc = StellarSDK;
|
|
52
|
+
const rpc = stellarWithRpc.rpc;
|
|
53
|
+
if (!rpc?.Server) {
|
|
54
|
+
throw new Error('SorobanRpc.Server not found in SDK');
|
|
55
|
+
}
|
|
56
|
+
this.server = new rpc.Server(config.rpcUrl);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new SmartWallet instance for a user
|
|
60
|
+
* @param ownerPublicKey - The public key that will own this wallet
|
|
61
|
+
* @param sourceKeypair - Keypair to pay for deployment and sign transactions
|
|
62
|
+
* @returns The contract ID of the newly deployed wallet
|
|
63
|
+
*/
|
|
64
|
+
async createWallet(ownerPublicKey, sourceKeypair) {
|
|
65
|
+
// 1. Deploy new contract instance from WASM hash
|
|
66
|
+
const contractId = await this.deployInstance(sourceKeypair);
|
|
67
|
+
// 2. Initialize the wallet with the owner
|
|
68
|
+
const wallet = new SmartWallet_1.SmartWallet({
|
|
69
|
+
contractId,
|
|
70
|
+
rpcUrl: this.rpcUrl,
|
|
71
|
+
networkPassphrase: this.networkPassphrase,
|
|
72
|
+
});
|
|
73
|
+
await wallet.initialize(ownerPublicKey, sourceKeypair);
|
|
74
|
+
return contractId;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Deploy a new contract instance from the WASM hash
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
async deployInstance(sourceKeypair) {
|
|
81
|
+
const sourceAccount = await this.server.getAccount(sourceKeypair.publicKey());
|
|
82
|
+
// Build deployment transaction using invokeHostFunction
|
|
83
|
+
const tx = new TransactionBuilder(sourceAccount, {
|
|
84
|
+
fee: '10000000', // Higher fee for deployment
|
|
85
|
+
networkPassphrase: this.networkPassphrase,
|
|
86
|
+
})
|
|
87
|
+
.addOperation(Operation.invokeHostFunction({
|
|
88
|
+
func: StellarSDK.xdr.HostFunction.hostFunctionTypeCreateContract(new StellarSDK.xdr.CreateContractArgs({
|
|
89
|
+
contractIdPreimage: StellarSDK.xdr.ContractIdPreimage.contractIdPreimageFromAddress(new StellarSDK.xdr.ContractIdPreimageFromAddress({
|
|
90
|
+
address: new StellarSDK.Address(sourceKeypair.publicKey()).toScAddress(),
|
|
91
|
+
salt: StellarSDK.Keypair.random().rawPublicKey(),
|
|
92
|
+
})),
|
|
93
|
+
executable: StellarSDK.xdr.ContractExecutable.contractExecutableWasm(Buffer.from(this.wasmHash, 'hex')),
|
|
94
|
+
})),
|
|
95
|
+
auth: [],
|
|
96
|
+
}))
|
|
97
|
+
.setTimeout(30)
|
|
98
|
+
.build();
|
|
99
|
+
// Sign and submit
|
|
100
|
+
const prepared = await this.server.prepareTransaction(tx);
|
|
101
|
+
prepared.sign(sourceKeypair);
|
|
102
|
+
const result = await (0, soroban_utils_1.submitSignedTransaction)(prepared, this.server);
|
|
103
|
+
// Extract contract ID from the transaction result
|
|
104
|
+
if (result.returnValue) {
|
|
105
|
+
// The return value is an ScAddress which needs to be converted
|
|
106
|
+
const scValToNative = StellarSDK.scValToNative;
|
|
107
|
+
const contractId = scValToNative(result.returnValue);
|
|
108
|
+
return contractId;
|
|
109
|
+
}
|
|
110
|
+
throw new Error('Failed to extract contract ID from deployment result');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.WalletFactory = WalletFactory;
|
|
114
|
+
//# sourceMappingURL=WalletFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WalletFactory.js","sourceRoot":"","sources":["../src/WalletFactory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAmD;AACnD,+CAA4C;AAM5C,mDAA0D;AAE1D,MAAM,EACJ,kBAAkB,EAClB,SAAS,GACV,GAAG,UAAU,CAAC;AAEf;;;GAGG;AACH,MAAa,aAAa;IAMxB,YAAY,MAAqB;QAC/B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC;QAElD,wBAAwB;QACxB,MAAM,cAAc,GAAG,UAA0C,CAAC;QAClE,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC;QAC/B,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;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E;oBACxE,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE;iBACjD,CAAC,CACH;gBACD,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,kBAAkB,CAAC,sBAAsB,CAClE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAClC;aACF,CAAC,CACH;YACD,IAAI,EAAE,EAAE;SACT,CAAC,CACH;aACA,UAAU,CAAC,EAAE,CAAC;aACd,KAAK,EAAE,CAAC;QAEX,kBAAkB;QAClB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;QAC1D,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAE7B,MAAM,MAAM,GAAG,MAAM,IAAA,uCAAuB,EAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAEpE,kDAAkD;QAClD,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YACvB,+DAA+D;YAC/D,MAAM,aAAa,GAAI,UAAkB,CAAC,aAAa,CAAC;YACxD,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,WAAkB,CAAC,CAAC;YAC5D,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;CACF;AA9FD,sCA8FC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { SmartWallet } from './SmartWallet';
|
|
2
|
+
export { WalletFactory } from './WalletFactory';
|
|
3
|
+
export * from './soroban-utils';
|
|
4
|
+
export { Session, WalletConfig, FactoryConfig, ContractMethod } from './types';
|
|
5
|
+
export * as StellarSDK from '@stellar/stellar-sdk';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG/E,OAAO,KAAK,UAAU,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.StellarSDK = exports.ContractMethod = exports.WalletFactory = exports.SmartWallet = void 0;
|
|
40
|
+
// Main SDK exports
|
|
41
|
+
var SmartWallet_1 = require("./SmartWallet");
|
|
42
|
+
Object.defineProperty(exports, "SmartWallet", { enumerable: true, get: function () { return SmartWallet_1.SmartWallet; } });
|
|
43
|
+
var WalletFactory_1 = require("./WalletFactory");
|
|
44
|
+
Object.defineProperty(exports, "WalletFactory", { enumerable: true, get: function () { return WalletFactory_1.WalletFactory; } });
|
|
45
|
+
__exportStar(require("./soroban-utils"), exports);
|
|
46
|
+
// Type exports
|
|
47
|
+
var types_1 = require("./types");
|
|
48
|
+
Object.defineProperty(exports, "ContractMethod", { enumerable: true, get: function () { return types_1.ContractMethod; } });
|
|
49
|
+
// Re-export Stellar SDK for convenience
|
|
50
|
+
exports.StellarSDK = __importStar(require("@stellar/stellar-sdk"));
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mBAAmB;AACnB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,kDAAgC;AAEhC,eAAe;AACf,iCAA+E;AAAhC,uGAAA,cAAc,OAAA;AAE7D,wCAAwC;AACxC,mEAAmD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as StellarSDK from '@stellar/stellar-sdk';
|
|
2
|
+
import { GetTransactionResponse, SorobanRpcServer, ContractMethod, ScVal } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Submit a transaction and wait for confirmation
|
|
5
|
+
*/
|
|
6
|
+
export declare function submitTransaction(tx: StellarSDK.Transaction, sourceKeypair: StellarSDK.Keypair, server: SorobanRpcServer): Promise<GetTransactionResponse>;
|
|
7
|
+
/**
|
|
8
|
+
* Submit an already signed transaction
|
|
9
|
+
*/
|
|
10
|
+
export declare function submitSignedTransaction(tx: StellarSDK.Transaction, server: SorobanRpcServer): Promise<GetTransactionResponse>;
|
|
11
|
+
/**
|
|
12
|
+
* Build a transaction with standard configuration
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildTransaction(contract: StellarSDK.Contract, server: SorobanRpcServer, networkPassphrase: string, sourceAccount: StellarSDK.Account, method: ContractMethod, ...args: ScVal[]): Promise<StellarSDK.Transaction>;
|
|
15
|
+
/**
|
|
16
|
+
* Build and submit a transaction
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildAndSubmitTransaction(contract: StellarSDK.Contract, server: SorobanRpcServer, networkPassphrase: string, sourceKeypair: StellarSDK.Keypair, method: ContractMethod, ...args: ScVal[]): Promise<GetTransactionResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Build a transaction for simulation (read-only queries)
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildSimulationTransaction(contract: StellarSDK.Contract, server: SorobanRpcServer, networkPassphrase: string, method: ContractMethod, ...args: ScVal[]): Promise<StellarSDK.Transaction>;
|
|
23
|
+
/**
|
|
24
|
+
* Execute simulation and extract result
|
|
25
|
+
*/
|
|
26
|
+
export declare function executeSimulation<T>(contract: StellarSDK.Contract, server: SorobanRpcServer, networkPassphrase: string, method: ContractMethod, ...args: ScVal[]): Promise<T>;
|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xB,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,cAAc,EACtB,GAAG,IAAI,EAAE,KAAK,EAAE,GACf,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAiBjC;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAC7B,MAAM,EAAE,gBAAgB,EACxB,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,cAAc,EACtB,GAAG,IAAI,EAAE,KAAK,EAAE,GACf,OAAO,CAAC,CAAC,CAAC,CAkBZ"}
|
|
@@ -0,0 +1,142 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.submitTransaction = submitTransaction;
|
|
37
|
+
exports.submitSignedTransaction = submitSignedTransaction;
|
|
38
|
+
exports.buildTransaction = buildTransaction;
|
|
39
|
+
exports.buildAndSubmitTransaction = buildAndSubmitTransaction;
|
|
40
|
+
exports.buildSimulationTransaction = buildSimulationTransaction;
|
|
41
|
+
exports.executeSimulation = executeSimulation;
|
|
42
|
+
const StellarSDK = __importStar(require("@stellar/stellar-sdk"));
|
|
43
|
+
const { TransactionBuilder, BASE_FEE, scValToNative, } = StellarSDK;
|
|
44
|
+
/**
|
|
45
|
+
* Submit a transaction and wait for confirmation
|
|
46
|
+
*/
|
|
47
|
+
async function submitTransaction(tx, sourceKeypair, server) {
|
|
48
|
+
const prepared = await server.prepareTransaction(tx);
|
|
49
|
+
prepared.sign(sourceKeypair);
|
|
50
|
+
return await submitSignedTransaction(prepared, server);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Submit an already signed transaction
|
|
54
|
+
*/
|
|
55
|
+
async function submitSignedTransaction(tx, server) {
|
|
56
|
+
const sendResponse = await server.sendTransaction(tx);
|
|
57
|
+
const stellarWithRpc = StellarSDK;
|
|
58
|
+
const GetTransactionStatus = stellarWithRpc.rpc.Api.GetTransactionStatus;
|
|
59
|
+
if (sendResponse.status === 'PENDING') {
|
|
60
|
+
let getResponse = await server.getTransaction(sendResponse.hash);
|
|
61
|
+
let attempts = 0;
|
|
62
|
+
const maxAttempts = 30; // 30 seconds max
|
|
63
|
+
while (getResponse.status === GetTransactionStatus.NOT_FOUND &&
|
|
64
|
+
attempts < maxAttempts) {
|
|
65
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
66
|
+
getResponse = await server.getTransaction(sendResponse.hash);
|
|
67
|
+
attempts++;
|
|
68
|
+
}
|
|
69
|
+
if (getResponse.status === GetTransactionStatus.SUCCESS) {
|
|
70
|
+
return getResponse;
|
|
71
|
+
}
|
|
72
|
+
else if (getResponse.status === GetTransactionStatus.FAILED) {
|
|
73
|
+
throw new Error(`Transaction failed: ${JSON.stringify(getResponse.resultXdr || 'Unknown error')}`);
|
|
74
|
+
}
|
|
75
|
+
else if (getResponse.status === GetTransactionStatus.NOT_FOUND) {
|
|
76
|
+
throw new Error('Transaction timed out - not found after 30 seconds');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new Error(`Transaction ended with status: ${getResponse.status}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (sendResponse.status === 'ERROR') {
|
|
83
|
+
// Extract error details from the response
|
|
84
|
+
let errorMessage = 'Unknown error';
|
|
85
|
+
// The response may have errorResult with detailed error info (not in types)
|
|
86
|
+
const errorResult = sendResponse.errorResult;
|
|
87
|
+
if (errorResult?._attributes?.result?._switch?.name) {
|
|
88
|
+
errorMessage = errorResult._attributes.result._switch.name;
|
|
89
|
+
}
|
|
90
|
+
else if (sendResponse.errorResultXdr) {
|
|
91
|
+
errorMessage = `XDR: ${sendResponse.errorResultXdr}`;
|
|
92
|
+
}
|
|
93
|
+
throw new Error(`Transaction submission error: ${errorMessage}`);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
throw new Error(`Unexpected transaction status: ${sendResponse.status}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Build a transaction with standard configuration
|
|
101
|
+
*/
|
|
102
|
+
async function buildTransaction(contract, server, networkPassphrase, sourceAccount, method, ...args) {
|
|
103
|
+
return new TransactionBuilder(sourceAccount, {
|
|
104
|
+
fee: BASE_FEE,
|
|
105
|
+
networkPassphrase: networkPassphrase,
|
|
106
|
+
})
|
|
107
|
+
.addOperation(contract.call(method, ...args))
|
|
108
|
+
.setTimeout(30)
|
|
109
|
+
.build();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Build and submit a transaction
|
|
113
|
+
*/
|
|
114
|
+
async function buildAndSubmitTransaction(contract, server, networkPassphrase, sourceKeypair, method, ...args) {
|
|
115
|
+
const sourceAccount = await server.getAccount(sourceKeypair.publicKey());
|
|
116
|
+
const tx = await buildTransaction(contract, server, networkPassphrase, sourceAccount, method, ...args);
|
|
117
|
+
return await submitTransaction(tx, sourceKeypair, server);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Build a transaction for simulation (read-only queries)
|
|
121
|
+
*/
|
|
122
|
+
async function buildSimulationTransaction(contract, server, networkPassphrase, method, ...args) {
|
|
123
|
+
// Use a dummy account for simulation
|
|
124
|
+
const stellarWithRpc = StellarSDK;
|
|
125
|
+
const Account = stellarWithRpc.Account;
|
|
126
|
+
const dummyAccount = new Account('GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF', '0');
|
|
127
|
+
return await buildTransaction(contract, server, networkPassphrase, dummyAccount, method, ...args);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Execute simulation and extract result
|
|
131
|
+
*/
|
|
132
|
+
async function executeSimulation(contract, server, networkPassphrase, method, ...args) {
|
|
133
|
+
const tx = await buildSimulationTransaction(contract, server, networkPassphrase, method, ...args);
|
|
134
|
+
const simulated = await server.simulateTransaction(tx);
|
|
135
|
+
const stellarWithRpc = StellarSDK;
|
|
136
|
+
const Api = stellarWithRpc.rpc.Api;
|
|
137
|
+
if (Api.isSimulationSuccess(simulated)) {
|
|
138
|
+
return scValToNative(simulated.result.retval);
|
|
139
|
+
}
|
|
140
|
+
throw new Error(`Failed to execute ${method}`);
|
|
141
|
+
}
|
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AAG,CACJ,CAAC;IAEF,OAAO,MAAM,gBAAgB,CAC3B,QAAQ,EACR,MAAM,EACN,iBAAiB,EACjB,YAAY,EACZ,MAAM,EACN,GAAG,IAAI,CACR,CAAC;AACJ,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,iBAAiB,CACrC,QAA6B,EAC7B,MAAwB,EACxB,iBAAyB,EACzB,MAAsB,EACtB,GAAG,IAAa;IAEhB,MAAM,EAAE,GAAG,MAAM,0BAA0B,CACzC,QAAQ,EACR,MAAM,EACN,iBAAiB,EACjB,MAAM,EACN,GAAG,IAAI,CACR,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;IAEvD,MAAM,cAAc,GAAG,UAA0C,CAAC;IAClE,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC;IAEnC,IAAI,GAAG,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;QACvC,OAAO,aAAa,CAAC,SAAS,CAAC,MAAO,CAAC,MAAe,CAAM,CAAC;IAC/D,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,MAAM,EAAE,CAAC,CAAC;AACjD,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import * as StellarSDK from '@stellar/stellar-sdk';
|
|
2
|
+
export type ScVal = any;
|
|
3
|
+
export declare enum ContractMethod {
|
|
4
|
+
Initialize = "initialize",
|
|
5
|
+
Execute = "execute",
|
|
6
|
+
CreateSession = "create_session",
|
|
7
|
+
ExecuteSession = "execute_session",
|
|
8
|
+
AddGuardians = "add_guardians",
|
|
9
|
+
Recover = "recover",
|
|
10
|
+
GetOwner = "get_owner",
|
|
11
|
+
GetGuardians = "get_guardians",
|
|
12
|
+
GetSession = "get_session"
|
|
13
|
+
}
|
|
14
|
+
interface BaseConfig {
|
|
15
|
+
rpcUrl: string;
|
|
16
|
+
networkPassphrase: string;
|
|
17
|
+
}
|
|
18
|
+
export interface WalletConfig extends BaseConfig {
|
|
19
|
+
contractId: string;
|
|
20
|
+
}
|
|
21
|
+
export interface FactoryConfig extends BaseConfig {
|
|
22
|
+
wasmHash: string;
|
|
23
|
+
}
|
|
24
|
+
export interface Session {
|
|
25
|
+
key: string;
|
|
26
|
+
limit: string;
|
|
27
|
+
spent: string;
|
|
28
|
+
expires_at: number;
|
|
29
|
+
}
|
|
30
|
+
export interface SorobanRpcServer {
|
|
31
|
+
getAccount(address: string): Promise<StellarSDK.Account>;
|
|
32
|
+
prepareTransaction(tx: StellarSDK.Transaction): Promise<StellarSDK.Transaction>;
|
|
33
|
+
sendTransaction(tx: StellarSDK.Transaction): Promise<SendTransactionResponse>;
|
|
34
|
+
getTransaction(hash: string): Promise<GetTransactionResponse>;
|
|
35
|
+
simulateTransaction(tx: StellarSDK.Transaction): Promise<SimulateTransactionResponse>;
|
|
36
|
+
readonly serverURL: URL;
|
|
37
|
+
}
|
|
38
|
+
export interface SendTransactionResponse {
|
|
39
|
+
status: 'PENDING' | 'ERROR' | 'DUPLICATE';
|
|
40
|
+
hash: string;
|
|
41
|
+
errorResultXdr?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface GetTransactionResponse {
|
|
44
|
+
status: TransactionStatus;
|
|
45
|
+
resultXdr?: string;
|
|
46
|
+
returnValue?: unknown;
|
|
47
|
+
}
|
|
48
|
+
export declare enum TransactionStatus {
|
|
49
|
+
SUCCESS = "SUCCESS",
|
|
50
|
+
FAILED = "FAILED",
|
|
51
|
+
NOT_FOUND = "NOT_FOUND"
|
|
52
|
+
}
|
|
53
|
+
export interface SimulateTransactionResponse {
|
|
54
|
+
result?: {
|
|
55
|
+
retval: unknown;
|
|
56
|
+
};
|
|
57
|
+
error?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface StellarApi {
|
|
60
|
+
isSimulationSuccess(response: SimulateTransactionResponse): boolean;
|
|
61
|
+
GetTransactionStatus: typeof TransactionStatus;
|
|
62
|
+
}
|
|
63
|
+
export interface StellarRpc {
|
|
64
|
+
Server: new (url: string) => SorobanRpcServer;
|
|
65
|
+
Api: StellarApi;
|
|
66
|
+
assembleTransaction: (tx: StellarSDK.Transaction, simulation: any) => StellarSDK.Transaction;
|
|
67
|
+
}
|
|
68
|
+
export interface StellarSDKWithRpc {
|
|
69
|
+
rpc: StellarRpc;
|
|
70
|
+
Account: typeof StellarSDK.Account;
|
|
71
|
+
scValToNative: (val: ScVal) => unknown;
|
|
72
|
+
nativeToScVal: (val: unknown, opts?: {
|
|
73
|
+
type?: string;
|
|
74
|
+
}) => ScVal;
|
|
75
|
+
}
|
|
76
|
+
export {};
|
|
77
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,sBAAsB,CAAC;AAKnD,MAAM,MAAM,KAAK,GAAG,GAAG,CAAC;AAGxB,oBAAY,cAAc;IACxB,UAAU,eAAe;IACzB,OAAO,YAAY;IACnB,aAAa,mBAAmB;IAChC,cAAc,oBAAoB;IAClC,YAAY,kBAAkB;IAC9B,OAAO,YAAY;IACnB,QAAQ,cAAc;IACtB,YAAY,kBAAkB;IAC9B,UAAU,gBAAgB;CAC3B;AAGD,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAGD,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAGD,MAA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AAG,EAAE,UAAU,CAAC;IAEhB,mBAAmB,EAAE,CAAC,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,KAAK,UAAU,CAAC,WAAW,CAAC;CAC9F;AAGD,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,EAAE,OAAO,UAAU,CAAC,OAAO,CAAC;IACnC,aAAa,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,CAAC;IACvC,aAAa,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,KAAK,CAAC;CAClE"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionStatus = exports.ContractMethod = void 0;
|
|
4
|
+
// Smart Wallet contract interface
|
|
5
|
+
var ContractMethod;
|
|
6
|
+
(function (ContractMethod) {
|
|
7
|
+
ContractMethod["Initialize"] = "initialize";
|
|
8
|
+
ContractMethod["Execute"] = "execute";
|
|
9
|
+
ContractMethod["CreateSession"] = "create_session";
|
|
10
|
+
ContractMethod["ExecuteSession"] = "execute_session";
|
|
11
|
+
ContractMethod["AddGuardians"] = "add_guardians";
|
|
12
|
+
ContractMethod["Recover"] = "recover";
|
|
13
|
+
ContractMethod["GetOwner"] = "get_owner";
|
|
14
|
+
ContractMethod["GetGuardians"] = "get_guardians";
|
|
15
|
+
ContractMethod["GetSession"] = "get_session";
|
|
16
|
+
})(ContractMethod || (exports.ContractMethod = ContractMethod = {}));
|
|
17
|
+
var TransactionStatus;
|
|
18
|
+
(function (TransactionStatus) {
|
|
19
|
+
TransactionStatus["SUCCESS"] = "SUCCESS";
|
|
20
|
+
TransactionStatus["FAILED"] = "FAILED";
|
|
21
|
+
TransactionStatus["NOT_FOUND"] = "NOT_FOUND";
|
|
22
|
+
})(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
|
|
23
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAOA,kCAAkC;AAClC,IAAY,cAUX;AAVD,WAAY,cAAc;IACxB,2CAAyB,CAAA;IACzB,qCAAmB,CAAA;IACnB,kDAAgC,CAAA;IAChC,oDAAkC,CAAA;IAClC,gDAA8B,CAAA;IAC9B,qCAAmB,CAAA;IACnB,wCAAsB,CAAA;IACtB,gDAA8B,CAAA;IAC9B,4CAA0B,CAAA;AAC5B,CAAC,EAVW,cAAc,8BAAd,cAAc,QAUzB;AA8CD,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,sCAAiB,CAAA;IACjB,4CAAuB,CAAA;AACzB,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stellar-aa-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Account Abstraction SDK for Stellar/Soroban - Session keys, social recovery, and smart contract wallets",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"prepublishOnly": "npm run build",
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"stellar",
|
|
19
|
+
"soroban",
|
|
20
|
+
"account-abstraction",
|
|
21
|
+
"session-keys",
|
|
22
|
+
"social-recovery",
|
|
23
|
+
"smart-wallets",
|
|
24
|
+
"web3",
|
|
25
|
+
"blockchain"
|
|
26
|
+
],
|
|
27
|
+
"author": "0xaplus",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"type": "commonjs",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/payfrom/stellar-aa-sdk.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/payfrom/stellar-aa-sdk/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/payfrom/stellar-aa-sdk#readme",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@stellar/stellar-sdk": "^14.4.3"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^25.0.3",
|
|
43
|
+
"typescript": "^5.9.3"
|
|
44
|
+
}
|
|
45
|
+
}
|