@adelos/sdk 0.1.1 → 0.1.2
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 +87 -59
- package/dist/index.d.mts +138 -42
- package/dist/index.d.ts +138 -42
- package/dist/index.js +351 -88
- package/dist/index.mjs +350 -90
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4,16 +4,32 @@ import {
|
|
|
4
4
|
PublicKey as PublicKey5,
|
|
5
5
|
SystemProgram,
|
|
6
6
|
Transaction as Transaction2,
|
|
7
|
-
TransactionInstruction as TransactionInstruction2
|
|
7
|
+
TransactionInstruction as TransactionInstruction2,
|
|
8
|
+
TransactionMessage,
|
|
9
|
+
VersionedTransaction
|
|
8
10
|
} from "@solana/web3.js";
|
|
9
11
|
|
|
10
12
|
// src/constants.ts
|
|
11
|
-
import { PublicKey } from "@solana/web3.js";
|
|
12
|
-
var
|
|
13
|
-
"7T1UxHJ6psKiQheKZXxANu6mhgsmgaX55eNKZZL5u4Rp"
|
|
13
|
+
import { PublicKey, clusterApiUrl } from "@solana/web3.js";
|
|
14
|
+
var PROGRAM_IDS = {
|
|
15
|
+
devnet: new PublicKey("7T1UxHJ6psKiQheKZXxANu6mhgsmgaX55eNKZZL5u4Rp"),
|
|
16
|
+
"mainnet-beta": new PublicKey("7T1UxHJ6psKiQheKZXxANu6mhgsmgaX55eNKZZL5u4Rp"),
|
|
17
|
+
// Update when deployed to mainnet
|
|
18
|
+
localnet: new PublicKey("7T1UxHJ6psKiQheKZXxANu6mhgsmgaX55eNKZZL5u4Rp")
|
|
19
|
+
};
|
|
20
|
+
var RPC_URLS = {
|
|
21
|
+
devnet: clusterApiUrl("devnet"),
|
|
22
|
+
"mainnet-beta": clusterApiUrl("mainnet-beta"),
|
|
23
|
+
localnet: "http://localhost:8899"
|
|
24
|
+
};
|
|
25
|
+
var PROGRAM_ID = PROGRAM_IDS.devnet;
|
|
26
|
+
var MEMO_PROGRAM_ID = new PublicKey(
|
|
27
|
+
"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"
|
|
14
28
|
);
|
|
15
29
|
var REGISTRY_SEED = "registry";
|
|
16
30
|
var REGISTRY_ACCOUNT_SIZE = 8 + 32 + 32 + 1;
|
|
31
|
+
var MEMO_PREFIX = "ADLSv1:";
|
|
32
|
+
var STEALTH_DOMAIN = "adelos:stealth:v1";
|
|
17
33
|
|
|
18
34
|
// src/utils.ts
|
|
19
35
|
import { PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
@@ -53,75 +69,246 @@ function getDiscriminator(instructionName) {
|
|
|
53
69
|
|
|
54
70
|
// src/idl.ts
|
|
55
71
|
var IDL = {
|
|
56
|
-
address: "7T1UxHJ6psKiQheKZXxANu6mhgsmgaX55eNKZZL5u4Rp",
|
|
57
|
-
metadata: {
|
|
58
|
-
name: "adelos_registry",
|
|
59
|
-
version: "0.1.0",
|
|
60
|
-
spec: "0.1.0"
|
|
72
|
+
"address": "7T1UxHJ6psKiQheKZXxANu6mhgsmgaX55eNKZZL5u4Rp",
|
|
73
|
+
"metadata": {
|
|
74
|
+
"name": "adelos_registry",
|
|
75
|
+
"version": "0.1.0",
|
|
76
|
+
"spec": "0.1.0",
|
|
77
|
+
"description": "Privacy Registry for Adelos Protocol"
|
|
61
78
|
},
|
|
62
|
-
instructions: [
|
|
79
|
+
"instructions": [
|
|
63
80
|
{
|
|
64
|
-
name: "
|
|
65
|
-
discriminator: [
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
"name": "close_registry",
|
|
82
|
+
"discriminator": [
|
|
83
|
+
76,
|
|
84
|
+
32,
|
|
85
|
+
154,
|
|
86
|
+
180,
|
|
87
|
+
51,
|
|
88
|
+
159,
|
|
89
|
+
218,
|
|
90
|
+
102
|
|
70
91
|
],
|
|
71
|
-
|
|
92
|
+
"accounts": [
|
|
93
|
+
{
|
|
94
|
+
"name": "owner",
|
|
95
|
+
"writable": true,
|
|
96
|
+
"signer": true,
|
|
97
|
+
"relations": [
|
|
98
|
+
"registry"
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "registry",
|
|
103
|
+
"writable": true,
|
|
104
|
+
"pda": {
|
|
105
|
+
"seeds": [
|
|
106
|
+
{
|
|
107
|
+
"kind": "const",
|
|
108
|
+
"value": [
|
|
109
|
+
114,
|
|
110
|
+
101,
|
|
111
|
+
103,
|
|
112
|
+
105,
|
|
113
|
+
115,
|
|
114
|
+
116,
|
|
115
|
+
114,
|
|
116
|
+
121
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"kind": "account",
|
|
121
|
+
"path": "owner"
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
"args": []
|
|
72
128
|
},
|
|
73
129
|
{
|
|
74
|
-
name: "
|
|
75
|
-
discriminator: [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
130
|
+
"name": "register_identity",
|
|
131
|
+
"discriminator": [
|
|
132
|
+
164,
|
|
133
|
+
118,
|
|
134
|
+
227,
|
|
135
|
+
177,
|
|
136
|
+
47,
|
|
137
|
+
176,
|
|
138
|
+
187,
|
|
139
|
+
248
|
|
79
140
|
],
|
|
80
|
-
|
|
141
|
+
"accounts": [
|
|
142
|
+
{
|
|
143
|
+
"name": "owner",
|
|
144
|
+
"writable": true,
|
|
145
|
+
"signer": true
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"name": "registry",
|
|
149
|
+
"writable": true,
|
|
150
|
+
"pda": {
|
|
151
|
+
"seeds": [
|
|
152
|
+
{
|
|
153
|
+
"kind": "const",
|
|
154
|
+
"value": [
|
|
155
|
+
114,
|
|
156
|
+
101,
|
|
157
|
+
103,
|
|
158
|
+
105,
|
|
159
|
+
115,
|
|
160
|
+
116,
|
|
161
|
+
114,
|
|
162
|
+
121
|
|
163
|
+
]
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"kind": "account",
|
|
167
|
+
"path": "owner"
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"name": "system_program",
|
|
174
|
+
"address": "11111111111111111111111111111111"
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
"args": [
|
|
178
|
+
{
|
|
179
|
+
"name": "meta_pubkey",
|
|
180
|
+
"type": {
|
|
181
|
+
"array": [
|
|
182
|
+
"u8",
|
|
183
|
+
32
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
]
|
|
81
188
|
},
|
|
82
189
|
{
|
|
83
|
-
name: "
|
|
84
|
-
discriminator: [
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
190
|
+
"name": "update_identity",
|
|
191
|
+
"discriminator": [
|
|
192
|
+
130,
|
|
193
|
+
54,
|
|
194
|
+
88,
|
|
195
|
+
104,
|
|
196
|
+
222,
|
|
197
|
+
124,
|
|
198
|
+
238,
|
|
199
|
+
252
|
|
200
|
+
],
|
|
201
|
+
"accounts": [
|
|
202
|
+
{
|
|
203
|
+
"name": "owner",
|
|
204
|
+
"writable": true,
|
|
205
|
+
"signer": true,
|
|
206
|
+
"relations": [
|
|
207
|
+
"registry"
|
|
208
|
+
]
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"name": "registry",
|
|
212
|
+
"writable": true,
|
|
213
|
+
"pda": {
|
|
214
|
+
"seeds": [
|
|
215
|
+
{
|
|
216
|
+
"kind": "const",
|
|
217
|
+
"value": [
|
|
218
|
+
114,
|
|
219
|
+
101,
|
|
220
|
+
103,
|
|
221
|
+
105,
|
|
222
|
+
115,
|
|
223
|
+
116,
|
|
224
|
+
114,
|
|
225
|
+
121
|
|
226
|
+
]
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"kind": "account",
|
|
230
|
+
"path": "owner"
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"name": "system_program",
|
|
237
|
+
"address": "11111111111111111111111111111111"
|
|
238
|
+
}
|
|
88
239
|
],
|
|
89
|
-
args: [
|
|
240
|
+
"args": [
|
|
241
|
+
{
|
|
242
|
+
"name": "new_meta_pubkey",
|
|
243
|
+
"type": {
|
|
244
|
+
"array": [
|
|
245
|
+
"u8",
|
|
246
|
+
32
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
]
|
|
90
251
|
}
|
|
91
252
|
],
|
|
92
|
-
accounts: [
|
|
253
|
+
"accounts": [
|
|
93
254
|
{
|
|
94
|
-
name: "RegistryAccount",
|
|
95
|
-
discriminator: [
|
|
255
|
+
"name": "RegistryAccount",
|
|
256
|
+
"discriminator": [
|
|
257
|
+
113,
|
|
258
|
+
93,
|
|
259
|
+
106,
|
|
260
|
+
201,
|
|
261
|
+
100,
|
|
262
|
+
166,
|
|
263
|
+
146,
|
|
264
|
+
98
|
|
265
|
+
]
|
|
96
266
|
}
|
|
97
267
|
],
|
|
98
|
-
|
|
268
|
+
"errors": [
|
|
269
|
+
{
|
|
270
|
+
"code": 6e3,
|
|
271
|
+
"name": "InvalidMetaPubkey",
|
|
272
|
+
"msg": "Invalid meta_pubkey"
|
|
273
|
+
},
|
|
99
274
|
{
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
275
|
+
"code": 6001,
|
|
276
|
+
"name": "Unauthorized",
|
|
277
|
+
"msg": "Unauthorized"
|
|
278
|
+
}
|
|
279
|
+
],
|
|
280
|
+
"types": [
|
|
281
|
+
{
|
|
282
|
+
"name": "RegistryAccount",
|
|
283
|
+
"type": {
|
|
284
|
+
"kind": "struct",
|
|
285
|
+
"fields": [
|
|
286
|
+
{
|
|
287
|
+
"name": "owner",
|
|
288
|
+
"type": "pubkey"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
"name": "meta_pubkey",
|
|
292
|
+
"type": {
|
|
293
|
+
"array": [
|
|
294
|
+
"u8",
|
|
295
|
+
32
|
|
296
|
+
]
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"name": "bump",
|
|
301
|
+
"type": "u8"
|
|
302
|
+
}
|
|
107
303
|
]
|
|
108
304
|
}
|
|
109
305
|
}
|
|
110
|
-
],
|
|
111
|
-
errors: [
|
|
112
|
-
{ code: 6e3, name: "InvalidMetaPubkey", msg: "Invalid meta_pubkey" },
|
|
113
|
-
{ code: 6001, name: "Unauthorized", msg: "Unauthorized" }
|
|
114
306
|
]
|
|
115
307
|
};
|
|
116
308
|
|
|
117
309
|
// src/crypto.ts
|
|
118
310
|
import { sha256 } from "@noble/hashes/sha256";
|
|
119
311
|
import * as ed from "@noble/ed25519";
|
|
120
|
-
ed.etc.sha512Sync = (...m) => {
|
|
121
|
-
const h = sha256.create();
|
|
122
|
-
m.forEach((msg) => h.update(msg));
|
|
123
|
-
return h.digest();
|
|
124
|
-
};
|
|
125
312
|
function generateEphemeralKeypair() {
|
|
126
313
|
const secretKey = ed.utils.randomPrivateKey();
|
|
127
314
|
const publicKey = ed.getPublicKey(secretKey);
|
|
@@ -139,7 +326,7 @@ async function computeSharedSecret(ephemeralSk, recipientMetaPubkey) {
|
|
|
139
326
|
}
|
|
140
327
|
function deriveStealthPubkey(metaPubkey, sharedSecret) {
|
|
141
328
|
const scalarBytes = sha256(
|
|
142
|
-
new Uint8Array([...sharedSecret, ...Buffer.from(
|
|
329
|
+
new Uint8Array([...sharedSecret, ...Buffer.from(STEALTH_DOMAIN)])
|
|
143
330
|
);
|
|
144
331
|
const scalar = ed.etc.mod(
|
|
145
332
|
BigInt("0x" + bytesToHex(scalarBytes)),
|
|
@@ -152,7 +339,7 @@ function deriveStealthPubkey(metaPubkey, sharedSecret) {
|
|
|
152
339
|
}
|
|
153
340
|
function recoverStealthSecretKey(metaSk, sharedSecret) {
|
|
154
341
|
const scalarBytes = sha256(
|
|
155
|
-
new Uint8Array([...sharedSecret, ...Buffer.from(
|
|
342
|
+
new Uint8Array([...sharedSecret, ...Buffer.from(STEALTH_DOMAIN)])
|
|
156
343
|
);
|
|
157
344
|
const scalar = ed.etc.mod(
|
|
158
345
|
BigInt("0x" + bytesToHex(scalarBytes)),
|
|
@@ -175,11 +362,11 @@ async function computeSharedSecretAsRecipient(metaSk, ephemeralPubkey) {
|
|
|
175
362
|
}
|
|
176
363
|
function generateStealthMemo(ephemeralPubkey) {
|
|
177
364
|
const pubkeyHex = bytesToHex(ephemeralPubkey);
|
|
178
|
-
return
|
|
365
|
+
return `${MEMO_PREFIX}${pubkeyHex}`;
|
|
179
366
|
}
|
|
180
367
|
function parseStealthMemo(memo) {
|
|
181
|
-
if (!memo.startsWith(
|
|
182
|
-
const pubkeyHex = memo.slice(
|
|
368
|
+
if (!memo.startsWith(MEMO_PREFIX)) return null;
|
|
369
|
+
const pubkeyHex = memo.slice(MEMO_PREFIX.length);
|
|
183
370
|
if (pubkeyHex.length !== 64) return null;
|
|
184
371
|
try {
|
|
185
372
|
return hexToBytes(pubkeyHex);
|
|
@@ -415,7 +602,7 @@ var LightClient = class _LightClient {
|
|
|
415
602
|
);
|
|
416
603
|
const memoIx = new TransactionInstruction({
|
|
417
604
|
keys: [],
|
|
418
|
-
programId:
|
|
605
|
+
programId: MEMO_PROGRAM_ID,
|
|
419
606
|
data: Buffer.from(memo, "utf-8")
|
|
420
607
|
});
|
|
421
608
|
const transaction = new Transaction().add(transferIx).add(memoIx);
|
|
@@ -445,6 +632,10 @@ var AdelosIndexer = class _AdelosIndexer {
|
|
|
445
632
|
}
|
|
446
633
|
/**
|
|
447
634
|
* Scans recent transactions for stealth transfers to a recipient
|
|
635
|
+
*
|
|
636
|
+
* IMPORTANT: We scan the Memo Program, NOT the metaPubkey!
|
|
637
|
+
* The metaPubkey should never appear in transactions - that's the whole point of stealth addresses.
|
|
638
|
+
* We scan memo program for ADLSv1: prefix, then use Trial Decryption to check if it's for us.
|
|
448
639
|
*
|
|
449
640
|
* @param metaSk - Recipient's meta secret key
|
|
450
641
|
* @param metaPubkey - Recipient's meta public key
|
|
@@ -455,7 +646,7 @@ var AdelosIndexer = class _AdelosIndexer {
|
|
|
455
646
|
const results = [];
|
|
456
647
|
try {
|
|
457
648
|
const signatures = await this.connection.getSignaturesForAddress(
|
|
458
|
-
|
|
649
|
+
MEMO_PROGRAM_ID,
|
|
459
650
|
{ limit }
|
|
460
651
|
);
|
|
461
652
|
for (const sigInfo of signatures) {
|
|
@@ -464,6 +655,8 @@ var AdelosIndexer = class _AdelosIndexer {
|
|
|
464
655
|
{ maxSupportedTransactionVersion: 0 }
|
|
465
656
|
);
|
|
466
657
|
if (!tx) continue;
|
|
658
|
+
const memo = this.extractMemo(tx);
|
|
659
|
+
if (!memo?.startsWith(MEMO_PREFIX)) continue;
|
|
467
660
|
const stealthTx = await this.parseStealthTransaction(
|
|
468
661
|
tx,
|
|
469
662
|
sigInfo.signature,
|
|
@@ -491,7 +684,7 @@ var AdelosIndexer = class _AdelosIndexer {
|
|
|
491
684
|
const results = [];
|
|
492
685
|
try {
|
|
493
686
|
const signatures = await this.connection.getSignaturesForAddress(
|
|
494
|
-
|
|
687
|
+
MEMO_PROGRAM_ID,
|
|
495
688
|
{ limit: 1e3, until: since }
|
|
496
689
|
);
|
|
497
690
|
for (const sigInfo of signatures) {
|
|
@@ -501,7 +694,7 @@ var AdelosIndexer = class _AdelosIndexer {
|
|
|
501
694
|
);
|
|
502
695
|
if (!tx) continue;
|
|
503
696
|
const memo = this.extractMemo(tx);
|
|
504
|
-
if (!memo?.startsWith(
|
|
697
|
+
if (!memo?.startsWith(MEMO_PREFIX)) continue;
|
|
505
698
|
const stealthTx = await this.parseStealthTransaction(
|
|
506
699
|
tx,
|
|
507
700
|
sigInfo.signature,
|
|
@@ -543,39 +736,49 @@ var AdelosIndexer = class _AdelosIndexer {
|
|
|
543
736
|
return null;
|
|
544
737
|
}
|
|
545
738
|
/**
|
|
546
|
-
* Parses a transaction to extract stealth transfer info
|
|
739
|
+
* Parses a transaction to extract stealth transfer info using Trial Decryption
|
|
740
|
+
*
|
|
741
|
+
* Trial Decryption: First compute expected stealth address, then find if it exists in tx accounts
|
|
547
742
|
*/
|
|
548
743
|
async parseStealthTransaction(tx, signature, metaSk, metaPubkey) {
|
|
549
744
|
const memo = this.extractMemo(tx);
|
|
550
745
|
if (!memo) return null;
|
|
551
746
|
const ephemeralPubkey = parseStealthMemo(memo);
|
|
552
747
|
if (!ephemeralPubkey) return null;
|
|
553
|
-
|
|
554
|
-
const postBalances = tx.meta?.postBalances || [];
|
|
555
|
-
const accounts = tx.transaction.message.accountKeys;
|
|
556
|
-
let stealthAddress = null;
|
|
557
|
-
let amount = BigInt(0);
|
|
558
|
-
let sender = null;
|
|
559
|
-
for (let i = 0; i < accounts.length; i++) {
|
|
560
|
-
const change = (postBalances[i] || 0) - (preBalances[i] || 0);
|
|
561
|
-
if (change > 0) {
|
|
562
|
-
stealthAddress = accounts[i].pubkey;
|
|
563
|
-
amount = BigInt(change);
|
|
564
|
-
} else if (change < 0 && i === 0) {
|
|
565
|
-
sender = accounts[i].pubkey;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
if (!stealthAddress) return null;
|
|
569
|
-
let isForMe = false;
|
|
748
|
+
let expectedStealthHex;
|
|
570
749
|
try {
|
|
571
750
|
const sharedSecret = await computeSharedSecretAsRecipient(
|
|
572
751
|
metaSk,
|
|
573
752
|
ephemeralPubkey
|
|
574
753
|
);
|
|
575
754
|
const expectedStealth = deriveStealthPubkey(metaPubkey, sharedSecret);
|
|
576
|
-
|
|
755
|
+
expectedStealthHex = bytesToHex(expectedStealth);
|
|
577
756
|
} catch (error) {
|
|
578
|
-
console.warn("Error
|
|
757
|
+
console.warn("Error computing expected stealth:", error);
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
const accounts = tx.transaction.message.accountKeys;
|
|
761
|
+
const preBalances = tx.meta?.preBalances || [];
|
|
762
|
+
const postBalances = tx.meta?.postBalances || [];
|
|
763
|
+
let stealthIndex = -1;
|
|
764
|
+
for (let i = 0; i < accounts.length; i++) {
|
|
765
|
+
const accountHex = bytesToHex(accounts[i].pubkey.toBytes());
|
|
766
|
+
if (accountHex === expectedStealthHex) {
|
|
767
|
+
stealthIndex = i;
|
|
768
|
+
break;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
if (stealthIndex === -1) return null;
|
|
772
|
+
const stealthAddress = accounts[stealthIndex].pubkey;
|
|
773
|
+
const change = (postBalances[stealthIndex] || 0) - (preBalances[stealthIndex] || 0);
|
|
774
|
+
const amount = BigInt(Math.max(change, 0));
|
|
775
|
+
let sender = null;
|
|
776
|
+
for (let i = 0; i < accounts.length; i++) {
|
|
777
|
+
const accChange = (postBalances[i] || 0) - (preBalances[i] || 0);
|
|
778
|
+
if (accChange < 0) {
|
|
779
|
+
sender = accounts[i].pubkey;
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
579
782
|
}
|
|
580
783
|
return {
|
|
581
784
|
signature,
|
|
@@ -585,7 +788,8 @@ var AdelosIndexer = class _AdelosIndexer {
|
|
|
585
788
|
stealthAddress,
|
|
586
789
|
amount,
|
|
587
790
|
ephemeralPubkey,
|
|
588
|
-
isForMe
|
|
791
|
+
isForMe: true
|
|
792
|
+
// If we reach here, it's definitely for us
|
|
589
793
|
};
|
|
590
794
|
}
|
|
591
795
|
/**
|
|
@@ -639,14 +843,14 @@ var AdelosIndexer = class _AdelosIndexer {
|
|
|
639
843
|
*/
|
|
640
844
|
async processWebhook(payload, metaSk, metaPubkey) {
|
|
641
845
|
let memo = null;
|
|
642
|
-
const
|
|
846
|
+
const memoProgramStr = MEMO_PROGRAM_ID.toBase58();
|
|
643
847
|
for (const ix of payload.instructions) {
|
|
644
|
-
if (ix.programId ===
|
|
848
|
+
if (ix.programId === memoProgramStr) {
|
|
645
849
|
memo = Buffer.from(ix.data, "base64").toString("utf-8");
|
|
646
850
|
break;
|
|
647
851
|
}
|
|
648
852
|
}
|
|
649
|
-
if (!memo?.startsWith(
|
|
853
|
+
if (!memo?.startsWith(MEMO_PREFIX)) return null;
|
|
650
854
|
const ephemeralPubkey = parseStealthMemo(memo);
|
|
651
855
|
if (!ephemeralPubkey) return null;
|
|
652
856
|
let stealthAddress = null;
|
|
@@ -703,7 +907,7 @@ var AdelosIndexer = class _AdelosIndexer {
|
|
|
703
907
|
webhookURL: webhookUrl,
|
|
704
908
|
transactionTypes: ["TRANSFER"],
|
|
705
909
|
accountAddresses: [
|
|
706
|
-
|
|
910
|
+
MEMO_PROGRAM_ID.toBase58()
|
|
707
911
|
],
|
|
708
912
|
webhookType: "enhanced"
|
|
709
913
|
})
|
|
@@ -724,10 +928,11 @@ function createIndexer(config) {
|
|
|
724
928
|
// src/index.ts
|
|
725
929
|
var AdelosSDK = class {
|
|
726
930
|
constructor(options = {}) {
|
|
727
|
-
this.
|
|
728
|
-
const rpcUrl = options.rpcUrl ??
|
|
931
|
+
this.cluster = options.cluster ?? "devnet";
|
|
932
|
+
const rpcUrl = options.rpcUrl ?? RPC_URLS[this.cluster];
|
|
729
933
|
this.connection = new Connection3(rpcUrl, "confirmed");
|
|
730
|
-
this.programId =
|
|
934
|
+
this.programId = PROGRAM_IDS[this.cluster];
|
|
935
|
+
this.heliusApiKey = options.heliusApiKey;
|
|
731
936
|
}
|
|
732
937
|
/**
|
|
733
938
|
* Derives the registry PDA for an owner
|
|
@@ -837,7 +1042,7 @@ var AdelosSDK = class {
|
|
|
837
1042
|
});
|
|
838
1043
|
}
|
|
839
1044
|
/**
|
|
840
|
-
* Creates a register transaction (unsigned)
|
|
1045
|
+
* Creates a register transaction (unsigned) - Legacy format
|
|
841
1046
|
*/
|
|
842
1047
|
async createRegisterTransaction(owner, metaPubkey) {
|
|
843
1048
|
const instruction = this.createRegisterInstruction(owner, metaPubkey);
|
|
@@ -847,7 +1052,21 @@ var AdelosSDK = class {
|
|
|
847
1052
|
return transaction;
|
|
848
1053
|
}
|
|
849
1054
|
/**
|
|
850
|
-
* Creates
|
|
1055
|
+
* Creates a register transaction (unsigned) - Versioned format (v0)
|
|
1056
|
+
* Recommended for modern Solana applications
|
|
1057
|
+
*/
|
|
1058
|
+
async createRegisterTransactionV0(owner, metaPubkey) {
|
|
1059
|
+
const instruction = this.createRegisterInstruction(owner, metaPubkey);
|
|
1060
|
+
const { blockhash } = await this.connection.getLatestBlockhash();
|
|
1061
|
+
const messageV0 = new TransactionMessage({
|
|
1062
|
+
payerKey: owner,
|
|
1063
|
+
recentBlockhash: blockhash,
|
|
1064
|
+
instructions: [instruction]
|
|
1065
|
+
}).compileToV0Message();
|
|
1066
|
+
return new VersionedTransaction(messageV0);
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Creates an update transaction (unsigned) - Legacy format
|
|
851
1070
|
*/
|
|
852
1071
|
async createUpdateTransaction(owner, newMetaPubkey) {
|
|
853
1072
|
const instruction = this.createUpdateInstruction(owner, newMetaPubkey);
|
|
@@ -857,7 +1076,20 @@ var AdelosSDK = class {
|
|
|
857
1076
|
return transaction;
|
|
858
1077
|
}
|
|
859
1078
|
/**
|
|
860
|
-
* Creates
|
|
1079
|
+
* Creates an update transaction (unsigned) - Versioned format (v0)
|
|
1080
|
+
*/
|
|
1081
|
+
async createUpdateTransactionV0(owner, newMetaPubkey) {
|
|
1082
|
+
const instruction = this.createUpdateInstruction(owner, newMetaPubkey);
|
|
1083
|
+
const { blockhash } = await this.connection.getLatestBlockhash();
|
|
1084
|
+
const messageV0 = new TransactionMessage({
|
|
1085
|
+
payerKey: owner,
|
|
1086
|
+
recentBlockhash: blockhash,
|
|
1087
|
+
instructions: [instruction]
|
|
1088
|
+
}).compileToV0Message();
|
|
1089
|
+
return new VersionedTransaction(messageV0);
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Creates a close transaction (unsigned) - Legacy format
|
|
861
1093
|
*/
|
|
862
1094
|
async createCloseTransaction(owner) {
|
|
863
1095
|
const instruction = this.createCloseInstruction(owner);
|
|
@@ -867,7 +1099,20 @@ var AdelosSDK = class {
|
|
|
867
1099
|
return transaction;
|
|
868
1100
|
}
|
|
869
1101
|
/**
|
|
870
|
-
*
|
|
1102
|
+
* Creates a close transaction (unsigned) - Versioned format (v0)
|
|
1103
|
+
*/
|
|
1104
|
+
async createCloseTransactionV0(owner) {
|
|
1105
|
+
const instruction = this.createCloseInstruction(owner);
|
|
1106
|
+
const { blockhash } = await this.connection.getLatestBlockhash();
|
|
1107
|
+
const messageV0 = new TransactionMessage({
|
|
1108
|
+
payerKey: owner,
|
|
1109
|
+
recentBlockhash: blockhash,
|
|
1110
|
+
instructions: [instruction]
|
|
1111
|
+
}).compileToV0Message();
|
|
1112
|
+
return new VersionedTransaction(messageV0);
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Sends a signed legacy transaction and confirms it
|
|
871
1116
|
*/
|
|
872
1117
|
async sendAndConfirm(signedTransaction) {
|
|
873
1118
|
const signature = await this.connection.sendRawTransaction(
|
|
@@ -876,6 +1121,16 @@ var AdelosSDK = class {
|
|
|
876
1121
|
await this.connection.confirmTransaction(signature, "confirmed");
|
|
877
1122
|
return signature;
|
|
878
1123
|
}
|
|
1124
|
+
/**
|
|
1125
|
+
* Sends a signed versioned transaction and confirms it
|
|
1126
|
+
*/
|
|
1127
|
+
async sendAndConfirmV0(signedTransaction) {
|
|
1128
|
+
const signature = await this.connection.sendRawTransaction(
|
|
1129
|
+
signedTransaction.serialize()
|
|
1130
|
+
);
|
|
1131
|
+
await this.connection.confirmTransaction(signature, "confirmed");
|
|
1132
|
+
return signature;
|
|
1133
|
+
}
|
|
879
1134
|
};
|
|
880
1135
|
export {
|
|
881
1136
|
AdelosIndexer,
|
|
@@ -883,9 +1138,14 @@ export {
|
|
|
883
1138
|
IDL,
|
|
884
1139
|
LIGHT_PROGRAM_IDS,
|
|
885
1140
|
LightClient,
|
|
1141
|
+
MEMO_PREFIX,
|
|
1142
|
+
MEMO_PROGRAM_ID,
|
|
886
1143
|
PROGRAM_ID,
|
|
1144
|
+
PROGRAM_IDS,
|
|
887
1145
|
REGISTRY_ACCOUNT_SIZE,
|
|
888
1146
|
REGISTRY_SEED,
|
|
1147
|
+
RPC_URLS,
|
|
1148
|
+
STEALTH_DOMAIN,
|
|
889
1149
|
bytesToHex,
|
|
890
1150
|
computeSharedSecret,
|
|
891
1151
|
computeSharedSecretAsRecipient,
|