stellar-contracts-kit 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 +434 -0
- package/dist/cli/generate.js +951 -0
- package/dist/index.cjs +844 -0
- package/dist/index.d.cts +95 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.js +831 -0
- package/dist/wallets/index.cjs +199 -0
- package/dist/wallets/index.d.cts +60 -0
- package/dist/wallets/index.d.ts +60 -0
- package/dist/wallets/index.js +191 -0
- package/package.json +72 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var freighter = require('@stellar/freighter-api');
|
|
4
|
+
var signerExtensionApi = require('@lobstrco/signer-extension-api');
|
|
5
|
+
var sdk = require('@cyphras/sdk');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var freighter__default = /*#__PURE__*/_interopDefault(freighter);
|
|
10
|
+
|
|
11
|
+
// src/wallets/freighter.ts
|
|
12
|
+
|
|
13
|
+
// src/errors/index.ts
|
|
14
|
+
var StellarContractError = class extends Error {
|
|
15
|
+
constructor(code, message, cause) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "StellarContractError";
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.cause = cause;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
function makeError(code, message, cause) {
|
|
23
|
+
return new StellarContractError(code, message, cause);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/wallets/freighter.ts
|
|
27
|
+
var FreighterAdapter = class {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.name = "Freighter";
|
|
30
|
+
this.installUrl = "https://freighter.app";
|
|
31
|
+
}
|
|
32
|
+
async isAvailable() {
|
|
33
|
+
const res = await freighter__default.default.isConnected();
|
|
34
|
+
return !res.error && res.isConnected === true;
|
|
35
|
+
}
|
|
36
|
+
async connect() {
|
|
37
|
+
const res = await freighter__default.default.requestAccess();
|
|
38
|
+
if (res.error) {
|
|
39
|
+
throw makeError("WALLET_REJECTED", res.error.message ?? "Freighter access denied");
|
|
40
|
+
}
|
|
41
|
+
return { address: res.address };
|
|
42
|
+
}
|
|
43
|
+
async disconnect() {
|
|
44
|
+
}
|
|
45
|
+
async getAddress() {
|
|
46
|
+
const res = await freighter__default.default.getAddress();
|
|
47
|
+
if (res.error) {
|
|
48
|
+
throw makeError("WALLET_NOT_CONNECTED", res.error.message ?? "Could not get Freighter address");
|
|
49
|
+
}
|
|
50
|
+
return res.address;
|
|
51
|
+
}
|
|
52
|
+
async getNetworkPassphrase() {
|
|
53
|
+
const res = await freighter__default.default.getNetwork();
|
|
54
|
+
if (res.error) {
|
|
55
|
+
throw makeError("RPC_ERROR", res.error.message ?? "Could not get Freighter network");
|
|
56
|
+
}
|
|
57
|
+
return res.networkPassphrase;
|
|
58
|
+
}
|
|
59
|
+
async signTransaction(xdr, opts) {
|
|
60
|
+
const signOpts = {
|
|
61
|
+
networkPassphrase: opts.networkPassphrase
|
|
62
|
+
};
|
|
63
|
+
if (opts.address !== void 0) signOpts.address = opts.address;
|
|
64
|
+
const res = await freighter__default.default.signTransaction(xdr, signOpts);
|
|
65
|
+
if (res.error) {
|
|
66
|
+
throw makeError("WALLET_REJECTED", res.error.message ?? "Freighter rejected transaction signing");
|
|
67
|
+
}
|
|
68
|
+
return res.signedTxXdr;
|
|
69
|
+
}
|
|
70
|
+
async signAuthEntry(entryXdr, opts) {
|
|
71
|
+
const signOpts = {
|
|
72
|
+
networkPassphrase: opts.networkPassphrase
|
|
73
|
+
};
|
|
74
|
+
if (opts.address !== void 0) signOpts.address = opts.address;
|
|
75
|
+
const res = await freighter__default.default.signAuthEntry(entryXdr, signOpts);
|
|
76
|
+
if (res.error) {
|
|
77
|
+
throw makeError("WALLET_REJECTED", res.error.message ?? "Freighter rejected auth entry signing");
|
|
78
|
+
}
|
|
79
|
+
if (!res.signedAuthEntry) {
|
|
80
|
+
throw makeError("WALLET_REJECTED", "Freighter returned null auth entry");
|
|
81
|
+
}
|
|
82
|
+
return res.signedAuthEntry;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var LobstrAdapter = class {
|
|
86
|
+
constructor() {
|
|
87
|
+
this.name = "Lobstr";
|
|
88
|
+
this.installUrl = "https://lobstr.co/";
|
|
89
|
+
}
|
|
90
|
+
async isAvailable() {
|
|
91
|
+
if (typeof window === "undefined") return false;
|
|
92
|
+
if (window.lobstrSignerExtension) return true;
|
|
93
|
+
return Promise.race([
|
|
94
|
+
signerExtensionApi.isConnected(),
|
|
95
|
+
new Promise((res) => setTimeout(() => res(false), 500))
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
async connect() {
|
|
99
|
+
try {
|
|
100
|
+
const address = await signerExtensionApi.getPublicKey();
|
|
101
|
+
return { address };
|
|
102
|
+
} catch (err) {
|
|
103
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
104
|
+
if (msg.toLowerCase().includes("reject") || msg.toLowerCase().includes("denied") || msg.toLowerCase().includes("cancel")) {
|
|
105
|
+
throw makeError("WALLET_REJECTED", "Lobstr connection was rejected by the user");
|
|
106
|
+
}
|
|
107
|
+
throw makeError("WALLET_REJECTED", `Lobstr connection failed: ${msg}`, err);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async disconnect() {
|
|
111
|
+
}
|
|
112
|
+
async getAddress() {
|
|
113
|
+
try {
|
|
114
|
+
return await signerExtensionApi.getPublicKey();
|
|
115
|
+
} catch (err) {
|
|
116
|
+
throw makeError("WALLET_NOT_CONNECTED", "Could not retrieve Lobstr public key. Make sure the wallet is connected.", err);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async getNetworkPassphrase() {
|
|
120
|
+
throw makeError(
|
|
121
|
+
"RPC_ERROR",
|
|
122
|
+
"Lobstr does not expose network info. Ensure your Lobstr extension is set to the same network as your kit config."
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
async signTransaction(xdr, _opts) {
|
|
126
|
+
try {
|
|
127
|
+
return await signerExtensionApi.signTransaction(xdr);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
130
|
+
if (msg.toLowerCase().includes("reject") || msg.toLowerCase().includes("denied") || msg.toLowerCase().includes("cancel")) {
|
|
131
|
+
throw makeError("WALLET_REJECTED", "Lobstr rejected transaction signing");
|
|
132
|
+
}
|
|
133
|
+
throw makeError("WALLET_REJECTED", `Lobstr signing failed: ${msg}`, err);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async signAuthEntry(_entryXdr, _opts) {
|
|
137
|
+
throw makeError(
|
|
138
|
+
"WALLET_REJECTED",
|
|
139
|
+
"Lobstr does not support signing individual auth entries. For multi-party auth contracts, use Freighter."
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
function toKitError(err) {
|
|
144
|
+
const c = err.code;
|
|
145
|
+
const m = err.message;
|
|
146
|
+
if (c === "REJECTED" || c === "USER_REJECTED") throw makeError("WALLET_REJECTED", m);
|
|
147
|
+
if (c === "TIMEOUT") throw makeError("TX_TIMEOUT", m);
|
|
148
|
+
if (c === "NETWORK_MISMATCH") throw makeError("WALLET_NETWORK_MISMATCH", m);
|
|
149
|
+
if (c === "UNAUTHORIZED" || c === "NOT_ALLOWED" || c === "NOT_CONNECTED" || c === "WALLET_LOCKED") {
|
|
150
|
+
throw makeError("WALLET_NOT_CONNECTED", m);
|
|
151
|
+
}
|
|
152
|
+
throw makeError("RPC_ERROR", m);
|
|
153
|
+
}
|
|
154
|
+
var CyphrasAdapter = class {
|
|
155
|
+
constructor() {
|
|
156
|
+
this.name = "Cyphras";
|
|
157
|
+
this.installUrl = "https://cyphras.com";
|
|
158
|
+
}
|
|
159
|
+
isAvailable() {
|
|
160
|
+
return sdk.isExtensionInstalled();
|
|
161
|
+
}
|
|
162
|
+
async connect() {
|
|
163
|
+
if (!sdk.isExtensionInstalled()) throw makeError("WALLET_NOT_FOUND", "Cyphras extension is not installed");
|
|
164
|
+
const res = await sdk.cyphras.stellar.connect();
|
|
165
|
+
if (res.error) toKitError(res.error);
|
|
166
|
+
return { address: res.address };
|
|
167
|
+
}
|
|
168
|
+
async disconnect() {
|
|
169
|
+
if (!sdk.isExtensionInstalled()) return;
|
|
170
|
+
await sdk.cyphras.stellar.disconnect();
|
|
171
|
+
}
|
|
172
|
+
async getAddress() {
|
|
173
|
+
const res = await sdk.cyphras.stellar.getAccount();
|
|
174
|
+
if (res.error) toKitError(res.error);
|
|
175
|
+
return res.address;
|
|
176
|
+
}
|
|
177
|
+
async getNetworkPassphrase() {
|
|
178
|
+
const res = await sdk.cyphras.stellar.getNetwork();
|
|
179
|
+
if (res.error) toKitError(res.error);
|
|
180
|
+
return res.networkPassphrase;
|
|
181
|
+
}
|
|
182
|
+
async signTransaction(xdr, _opts) {
|
|
183
|
+
const res = await sdk.cyphras.stellar.sign(xdr);
|
|
184
|
+
if (res.error) toKitError(res.error);
|
|
185
|
+
return res.signedTxXdr;
|
|
186
|
+
}
|
|
187
|
+
async signAuthEntry(entryXdr, opts) {
|
|
188
|
+
const res = await sdk.cyphras.stellar.sign(entryXdr, {
|
|
189
|
+
type: "authEntry",
|
|
190
|
+
networkPassphrase: opts.networkPassphrase
|
|
191
|
+
});
|
|
192
|
+
if (res.error) toKitError(res.error);
|
|
193
|
+
return res.signedAuthEntry;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
exports.CyphrasAdapter = CyphrasAdapter;
|
|
198
|
+
exports.FreighterAdapter = FreighterAdapter;
|
|
199
|
+
exports.LobstrAdapter = LobstrAdapter;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
interface ConnectResult {
|
|
2
|
+
address: string;
|
|
3
|
+
}
|
|
4
|
+
interface SignTransactionOpts {
|
|
5
|
+
networkPassphrase: string;
|
|
6
|
+
address?: string;
|
|
7
|
+
}
|
|
8
|
+
interface SignAuthEntryOpts {
|
|
9
|
+
networkPassphrase: string;
|
|
10
|
+
address?: string;
|
|
11
|
+
}
|
|
12
|
+
interface WalletAdapter {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly installUrl: string;
|
|
15
|
+
isAvailable(): boolean | Promise<boolean>;
|
|
16
|
+
connect(): Promise<ConnectResult>;
|
|
17
|
+
disconnect(): Promise<void>;
|
|
18
|
+
getAddress(): Promise<string>;
|
|
19
|
+
getNetworkPassphrase(): Promise<string>;
|
|
20
|
+
signTransaction(xdr: string, opts: SignTransactionOpts): Promise<string>;
|
|
21
|
+
signAuthEntry(entryXdr: string, opts: SignAuthEntryOpts): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare class FreighterAdapter implements WalletAdapter {
|
|
25
|
+
readonly name = "Freighter";
|
|
26
|
+
readonly installUrl = "https://freighter.app";
|
|
27
|
+
isAvailable(): Promise<boolean>;
|
|
28
|
+
connect(): Promise<ConnectResult>;
|
|
29
|
+
disconnect(): Promise<void>;
|
|
30
|
+
getAddress(): Promise<string>;
|
|
31
|
+
getNetworkPassphrase(): Promise<string>;
|
|
32
|
+
signTransaction(xdr: string, opts: SignTransactionOpts): Promise<string>;
|
|
33
|
+
signAuthEntry(entryXdr: string, opts: SignAuthEntryOpts): Promise<string>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare class LobstrAdapter implements WalletAdapter {
|
|
37
|
+
readonly name = "Lobstr";
|
|
38
|
+
readonly installUrl = "https://lobstr.co/";
|
|
39
|
+
isAvailable(): Promise<boolean>;
|
|
40
|
+
connect(): Promise<ConnectResult>;
|
|
41
|
+
disconnect(): Promise<void>;
|
|
42
|
+
getAddress(): Promise<string>;
|
|
43
|
+
getNetworkPassphrase(): Promise<string>;
|
|
44
|
+
signTransaction(xdr: string, _opts: SignTransactionOpts): Promise<string>;
|
|
45
|
+
signAuthEntry(_entryXdr: string, _opts: SignAuthEntryOpts): Promise<string>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare class CyphrasAdapter implements WalletAdapter {
|
|
49
|
+
readonly name = "Cyphras";
|
|
50
|
+
readonly installUrl = "https://cyphras.com";
|
|
51
|
+
isAvailable(): boolean;
|
|
52
|
+
connect(): Promise<ConnectResult>;
|
|
53
|
+
disconnect(): Promise<void>;
|
|
54
|
+
getAddress(): Promise<string>;
|
|
55
|
+
getNetworkPassphrase(): Promise<string>;
|
|
56
|
+
signTransaction(xdr: string, _opts: SignTransactionOpts): Promise<string>;
|
|
57
|
+
signAuthEntry(entryXdr: string, opts: SignAuthEntryOpts): Promise<string>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { type ConnectResult, CyphrasAdapter, FreighterAdapter, LobstrAdapter, type SignAuthEntryOpts, type SignTransactionOpts, type WalletAdapter };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
interface ConnectResult {
|
|
2
|
+
address: string;
|
|
3
|
+
}
|
|
4
|
+
interface SignTransactionOpts {
|
|
5
|
+
networkPassphrase: string;
|
|
6
|
+
address?: string;
|
|
7
|
+
}
|
|
8
|
+
interface SignAuthEntryOpts {
|
|
9
|
+
networkPassphrase: string;
|
|
10
|
+
address?: string;
|
|
11
|
+
}
|
|
12
|
+
interface WalletAdapter {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly installUrl: string;
|
|
15
|
+
isAvailable(): boolean | Promise<boolean>;
|
|
16
|
+
connect(): Promise<ConnectResult>;
|
|
17
|
+
disconnect(): Promise<void>;
|
|
18
|
+
getAddress(): Promise<string>;
|
|
19
|
+
getNetworkPassphrase(): Promise<string>;
|
|
20
|
+
signTransaction(xdr: string, opts: SignTransactionOpts): Promise<string>;
|
|
21
|
+
signAuthEntry(entryXdr: string, opts: SignAuthEntryOpts): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare class FreighterAdapter implements WalletAdapter {
|
|
25
|
+
readonly name = "Freighter";
|
|
26
|
+
readonly installUrl = "https://freighter.app";
|
|
27
|
+
isAvailable(): Promise<boolean>;
|
|
28
|
+
connect(): Promise<ConnectResult>;
|
|
29
|
+
disconnect(): Promise<void>;
|
|
30
|
+
getAddress(): Promise<string>;
|
|
31
|
+
getNetworkPassphrase(): Promise<string>;
|
|
32
|
+
signTransaction(xdr: string, opts: SignTransactionOpts): Promise<string>;
|
|
33
|
+
signAuthEntry(entryXdr: string, opts: SignAuthEntryOpts): Promise<string>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare class LobstrAdapter implements WalletAdapter {
|
|
37
|
+
readonly name = "Lobstr";
|
|
38
|
+
readonly installUrl = "https://lobstr.co/";
|
|
39
|
+
isAvailable(): Promise<boolean>;
|
|
40
|
+
connect(): Promise<ConnectResult>;
|
|
41
|
+
disconnect(): Promise<void>;
|
|
42
|
+
getAddress(): Promise<string>;
|
|
43
|
+
getNetworkPassphrase(): Promise<string>;
|
|
44
|
+
signTransaction(xdr: string, _opts: SignTransactionOpts): Promise<string>;
|
|
45
|
+
signAuthEntry(_entryXdr: string, _opts: SignAuthEntryOpts): Promise<string>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare class CyphrasAdapter implements WalletAdapter {
|
|
49
|
+
readonly name = "Cyphras";
|
|
50
|
+
readonly installUrl = "https://cyphras.com";
|
|
51
|
+
isAvailable(): boolean;
|
|
52
|
+
connect(): Promise<ConnectResult>;
|
|
53
|
+
disconnect(): Promise<void>;
|
|
54
|
+
getAddress(): Promise<string>;
|
|
55
|
+
getNetworkPassphrase(): Promise<string>;
|
|
56
|
+
signTransaction(xdr: string, _opts: SignTransactionOpts): Promise<string>;
|
|
57
|
+
signAuthEntry(entryXdr: string, opts: SignAuthEntryOpts): Promise<string>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { type ConnectResult, CyphrasAdapter, FreighterAdapter, LobstrAdapter, type SignAuthEntryOpts, type SignTransactionOpts, type WalletAdapter };
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import freighter from '@stellar/freighter-api';
|
|
2
|
+
import { isConnected, getPublicKey, signTransaction } from '@lobstrco/signer-extension-api';
|
|
3
|
+
import { isExtensionInstalled, cyphras } from '@cyphras/sdk';
|
|
4
|
+
|
|
5
|
+
// src/wallets/freighter.ts
|
|
6
|
+
|
|
7
|
+
// src/errors/index.ts
|
|
8
|
+
var StellarContractError = class extends Error {
|
|
9
|
+
constructor(code, message, cause) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "StellarContractError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.cause = cause;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
function makeError(code, message, cause) {
|
|
17
|
+
return new StellarContractError(code, message, cause);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/wallets/freighter.ts
|
|
21
|
+
var FreighterAdapter = class {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.name = "Freighter";
|
|
24
|
+
this.installUrl = "https://freighter.app";
|
|
25
|
+
}
|
|
26
|
+
async isAvailable() {
|
|
27
|
+
const res = await freighter.isConnected();
|
|
28
|
+
return !res.error && res.isConnected === true;
|
|
29
|
+
}
|
|
30
|
+
async connect() {
|
|
31
|
+
const res = await freighter.requestAccess();
|
|
32
|
+
if (res.error) {
|
|
33
|
+
throw makeError("WALLET_REJECTED", res.error.message ?? "Freighter access denied");
|
|
34
|
+
}
|
|
35
|
+
return { address: res.address };
|
|
36
|
+
}
|
|
37
|
+
async disconnect() {
|
|
38
|
+
}
|
|
39
|
+
async getAddress() {
|
|
40
|
+
const res = await freighter.getAddress();
|
|
41
|
+
if (res.error) {
|
|
42
|
+
throw makeError("WALLET_NOT_CONNECTED", res.error.message ?? "Could not get Freighter address");
|
|
43
|
+
}
|
|
44
|
+
return res.address;
|
|
45
|
+
}
|
|
46
|
+
async getNetworkPassphrase() {
|
|
47
|
+
const res = await freighter.getNetwork();
|
|
48
|
+
if (res.error) {
|
|
49
|
+
throw makeError("RPC_ERROR", res.error.message ?? "Could not get Freighter network");
|
|
50
|
+
}
|
|
51
|
+
return res.networkPassphrase;
|
|
52
|
+
}
|
|
53
|
+
async signTransaction(xdr, opts) {
|
|
54
|
+
const signOpts = {
|
|
55
|
+
networkPassphrase: opts.networkPassphrase
|
|
56
|
+
};
|
|
57
|
+
if (opts.address !== void 0) signOpts.address = opts.address;
|
|
58
|
+
const res = await freighter.signTransaction(xdr, signOpts);
|
|
59
|
+
if (res.error) {
|
|
60
|
+
throw makeError("WALLET_REJECTED", res.error.message ?? "Freighter rejected transaction signing");
|
|
61
|
+
}
|
|
62
|
+
return res.signedTxXdr;
|
|
63
|
+
}
|
|
64
|
+
async signAuthEntry(entryXdr, opts) {
|
|
65
|
+
const signOpts = {
|
|
66
|
+
networkPassphrase: opts.networkPassphrase
|
|
67
|
+
};
|
|
68
|
+
if (opts.address !== void 0) signOpts.address = opts.address;
|
|
69
|
+
const res = await freighter.signAuthEntry(entryXdr, signOpts);
|
|
70
|
+
if (res.error) {
|
|
71
|
+
throw makeError("WALLET_REJECTED", res.error.message ?? "Freighter rejected auth entry signing");
|
|
72
|
+
}
|
|
73
|
+
if (!res.signedAuthEntry) {
|
|
74
|
+
throw makeError("WALLET_REJECTED", "Freighter returned null auth entry");
|
|
75
|
+
}
|
|
76
|
+
return res.signedAuthEntry;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var LobstrAdapter = class {
|
|
80
|
+
constructor() {
|
|
81
|
+
this.name = "Lobstr";
|
|
82
|
+
this.installUrl = "https://lobstr.co/";
|
|
83
|
+
}
|
|
84
|
+
async isAvailable() {
|
|
85
|
+
if (typeof window === "undefined") return false;
|
|
86
|
+
if (window.lobstrSignerExtension) return true;
|
|
87
|
+
return Promise.race([
|
|
88
|
+
isConnected(),
|
|
89
|
+
new Promise((res) => setTimeout(() => res(false), 500))
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
async connect() {
|
|
93
|
+
try {
|
|
94
|
+
const address = await getPublicKey();
|
|
95
|
+
return { address };
|
|
96
|
+
} catch (err) {
|
|
97
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
98
|
+
if (msg.toLowerCase().includes("reject") || msg.toLowerCase().includes("denied") || msg.toLowerCase().includes("cancel")) {
|
|
99
|
+
throw makeError("WALLET_REJECTED", "Lobstr connection was rejected by the user");
|
|
100
|
+
}
|
|
101
|
+
throw makeError("WALLET_REJECTED", `Lobstr connection failed: ${msg}`, err);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async disconnect() {
|
|
105
|
+
}
|
|
106
|
+
async getAddress() {
|
|
107
|
+
try {
|
|
108
|
+
return await getPublicKey();
|
|
109
|
+
} catch (err) {
|
|
110
|
+
throw makeError("WALLET_NOT_CONNECTED", "Could not retrieve Lobstr public key. Make sure the wallet is connected.", err);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async getNetworkPassphrase() {
|
|
114
|
+
throw makeError(
|
|
115
|
+
"RPC_ERROR",
|
|
116
|
+
"Lobstr does not expose network info. Ensure your Lobstr extension is set to the same network as your kit config."
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
async signTransaction(xdr, _opts) {
|
|
120
|
+
try {
|
|
121
|
+
return await signTransaction(xdr);
|
|
122
|
+
} catch (err) {
|
|
123
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
124
|
+
if (msg.toLowerCase().includes("reject") || msg.toLowerCase().includes("denied") || msg.toLowerCase().includes("cancel")) {
|
|
125
|
+
throw makeError("WALLET_REJECTED", "Lobstr rejected transaction signing");
|
|
126
|
+
}
|
|
127
|
+
throw makeError("WALLET_REJECTED", `Lobstr signing failed: ${msg}`, err);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async signAuthEntry(_entryXdr, _opts) {
|
|
131
|
+
throw makeError(
|
|
132
|
+
"WALLET_REJECTED",
|
|
133
|
+
"Lobstr does not support signing individual auth entries. For multi-party auth contracts, use Freighter."
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
function toKitError(err) {
|
|
138
|
+
const c = err.code;
|
|
139
|
+
const m = err.message;
|
|
140
|
+
if (c === "REJECTED" || c === "USER_REJECTED") throw makeError("WALLET_REJECTED", m);
|
|
141
|
+
if (c === "TIMEOUT") throw makeError("TX_TIMEOUT", m);
|
|
142
|
+
if (c === "NETWORK_MISMATCH") throw makeError("WALLET_NETWORK_MISMATCH", m);
|
|
143
|
+
if (c === "UNAUTHORIZED" || c === "NOT_ALLOWED" || c === "NOT_CONNECTED" || c === "WALLET_LOCKED") {
|
|
144
|
+
throw makeError("WALLET_NOT_CONNECTED", m);
|
|
145
|
+
}
|
|
146
|
+
throw makeError("RPC_ERROR", m);
|
|
147
|
+
}
|
|
148
|
+
var CyphrasAdapter = class {
|
|
149
|
+
constructor() {
|
|
150
|
+
this.name = "Cyphras";
|
|
151
|
+
this.installUrl = "https://cyphras.com";
|
|
152
|
+
}
|
|
153
|
+
isAvailable() {
|
|
154
|
+
return isExtensionInstalled();
|
|
155
|
+
}
|
|
156
|
+
async connect() {
|
|
157
|
+
if (!isExtensionInstalled()) throw makeError("WALLET_NOT_FOUND", "Cyphras extension is not installed");
|
|
158
|
+
const res = await cyphras.stellar.connect();
|
|
159
|
+
if (res.error) toKitError(res.error);
|
|
160
|
+
return { address: res.address };
|
|
161
|
+
}
|
|
162
|
+
async disconnect() {
|
|
163
|
+
if (!isExtensionInstalled()) return;
|
|
164
|
+
await cyphras.stellar.disconnect();
|
|
165
|
+
}
|
|
166
|
+
async getAddress() {
|
|
167
|
+
const res = await cyphras.stellar.getAccount();
|
|
168
|
+
if (res.error) toKitError(res.error);
|
|
169
|
+
return res.address;
|
|
170
|
+
}
|
|
171
|
+
async getNetworkPassphrase() {
|
|
172
|
+
const res = await cyphras.stellar.getNetwork();
|
|
173
|
+
if (res.error) toKitError(res.error);
|
|
174
|
+
return res.networkPassphrase;
|
|
175
|
+
}
|
|
176
|
+
async signTransaction(xdr, _opts) {
|
|
177
|
+
const res = await cyphras.stellar.sign(xdr);
|
|
178
|
+
if (res.error) toKitError(res.error);
|
|
179
|
+
return res.signedTxXdr;
|
|
180
|
+
}
|
|
181
|
+
async signAuthEntry(entryXdr, opts) {
|
|
182
|
+
const res = await cyphras.stellar.sign(entryXdr, {
|
|
183
|
+
type: "authEntry",
|
|
184
|
+
networkPassphrase: opts.networkPassphrase
|
|
185
|
+
});
|
|
186
|
+
if (res.error) toKitError(res.error);
|
|
187
|
+
return res.signedAuthEntry;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export { CyphrasAdapter, FreighterAdapter, LobstrAdapter };
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stellar-contracts-kit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for Soroban smart contract interactions on Stellar",
|
|
5
|
+
"author": "fxjrin",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/fxjrin/stellar-contracts-kit.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"stellar",
|
|
13
|
+
"soroban",
|
|
14
|
+
"smart-contract",
|
|
15
|
+
"blockchain",
|
|
16
|
+
"typescript",
|
|
17
|
+
"sdk",
|
|
18
|
+
"cli",
|
|
19
|
+
"type-generator",
|
|
20
|
+
"wallet",
|
|
21
|
+
"dapp",
|
|
22
|
+
"freighter",
|
|
23
|
+
"lobstr",
|
|
24
|
+
"cyphras",
|
|
25
|
+
"web3"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"type": "module",
|
|
31
|
+
"main": "./dist/index.cjs",
|
|
32
|
+
"module": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"require": "./dist/index.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./wallets": {
|
|
41
|
+
"types": "./dist/wallets/index.d.ts",
|
|
42
|
+
"import": "./dist/wallets/index.js",
|
|
43
|
+
"require": "./dist/wallets/index.cjs"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"bin": {
|
|
47
|
+
"stellar-contracts-kit": "./dist/cli/generate.js",
|
|
48
|
+
"sck": "./dist/cli/generate.js"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist"
|
|
52
|
+
],
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"dev": "tsup --watch",
|
|
56
|
+
"typecheck": "tsc --noEmit",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"test:watch": "vitest"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@cyphras/sdk": "^0.1.0",
|
|
62
|
+
"@lobstrco/signer-extension-api": "^2.0.0",
|
|
63
|
+
"@stellar/freighter-api": "^6.0.0",
|
|
64
|
+
"@stellar/stellar-sdk": "^15.1.0"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/node": "^22.13.0",
|
|
68
|
+
"tsup": "^8.4.0",
|
|
69
|
+
"typescript": "^5.7.3",
|
|
70
|
+
"vitest": "^4.1.7"
|
|
71
|
+
}
|
|
72
|
+
}
|