privacycash 1.0.19 → 1.0.21
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/dist/getUtxos.d.ts +2 -1
- package/dist/getUtxos.js +10 -3
- package/dist/getUtxosSPL.d.ts +2 -1
- package/dist/getUtxosSPL.js +10 -3
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/constants.js +1 -1
- package/package.json +1 -1
- package/src/getUtxos.ts +13 -3
- package/src/getUtxosSPL.ts +12 -3
- package/src/utils/constants.ts +1 -1
package/dist/getUtxos.d.ts
CHANGED
|
@@ -9,12 +9,13 @@ export declare function localstorageKey(key: PublicKey): string;
|
|
|
9
9
|
* @param setStatus A global state updator. Set live status message showing on webpage
|
|
10
10
|
* @returns Array of decrypted UTXOs that belong to the user
|
|
11
11
|
*/
|
|
12
|
-
export declare function getUtxos({ publicKey, connection, encryptionService, storage, abortSignal }: {
|
|
12
|
+
export declare function getUtxos({ publicKey, connection, encryptionService, storage, abortSignal, offset }: {
|
|
13
13
|
publicKey: PublicKey;
|
|
14
14
|
connection: Connection;
|
|
15
15
|
encryptionService: EncryptionService;
|
|
16
16
|
storage: Storage;
|
|
17
17
|
abortSignal?: AbortSignal;
|
|
18
|
+
offset?: number;
|
|
18
19
|
}): Promise<Utxo[]>;
|
|
19
20
|
/**
|
|
20
21
|
* Check if a UTXO has been spent
|
package/dist/getUtxos.js
CHANGED
|
@@ -26,7 +26,7 @@ let decryptionTaskFinished = 0;
|
|
|
26
26
|
* @param setStatus A global state updator. Set live status message showing on webpage
|
|
27
27
|
* @returns Array of decrypted UTXOs that belong to the user
|
|
28
28
|
*/
|
|
29
|
-
export async function getUtxos({ publicKey, connection, encryptionService, storage, abortSignal }) {
|
|
29
|
+
export async function getUtxos({ publicKey, connection, encryptionService, storage, abortSignal, offset }) {
|
|
30
30
|
let valid_utxos = [];
|
|
31
31
|
let valid_strings = [];
|
|
32
32
|
let history_indexes = [];
|
|
@@ -38,15 +38,22 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
38
38
|
roundStartIndex = 0;
|
|
39
39
|
}
|
|
40
40
|
decryptionTaskFinished = 0;
|
|
41
|
+
if (!offset) {
|
|
42
|
+
offset = 0;
|
|
43
|
+
}
|
|
44
|
+
roundStartIndex = Math.max(offset, roundStartIndex);
|
|
41
45
|
while (true) {
|
|
42
46
|
if (abortSignal?.aborted) {
|
|
43
47
|
throw new Error('aborted');
|
|
44
48
|
}
|
|
45
49
|
let offsetStr = storage.getItem(LSK_FETCH_OFFSET + localstorageKey(publicKey));
|
|
46
50
|
let fetch_utxo_offset = offsetStr ? Number(offsetStr) : 0;
|
|
51
|
+
if (offset) {
|
|
52
|
+
fetch_utxo_offset = Math.max(offset, fetch_utxo_offset);
|
|
53
|
+
}
|
|
47
54
|
let fetch_utxo_end = fetch_utxo_offset + FETCH_UTXOS_GROUP_SIZE;
|
|
48
55
|
let fetch_utxo_url = `${RELAYER_API_URL}/utxos/range?start=${fetch_utxo_offset}&end=${fetch_utxo_end}`;
|
|
49
|
-
let fetched = await fetchUserUtxos({ publicKey, connection, url: fetch_utxo_url, encryptionService, storage });
|
|
56
|
+
let fetched = await fetchUserUtxos({ publicKey, connection, url: fetch_utxo_url, encryptionService, storage, initOffset: offset });
|
|
50
57
|
let am = 0;
|
|
51
58
|
const nonZeroUtxos = [];
|
|
52
59
|
const nonZeroEncrypted = [];
|
|
@@ -96,7 +103,7 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
96
103
|
storage.setItem(LSK_ENCRYPTED_OUTPUTS + localstorageKey(publicKey), JSON.stringify(valid_strings));
|
|
97
104
|
return valid_utxos;
|
|
98
105
|
}
|
|
99
|
-
async function fetchUserUtxos({ publicKey, connection, url, storage, encryptionService }) {
|
|
106
|
+
async function fetchUserUtxos({ publicKey, connection, url, storage, encryptionService, initOffset }) {
|
|
100
107
|
const lightWasm = await WasmFactory.getInstance();
|
|
101
108
|
// Derive the UTXO keypair from the wallet keypair
|
|
102
109
|
const utxoPrivateKey = encryptionService.deriveUtxoPrivateKey();
|
package/dist/getUtxosSPL.d.ts
CHANGED
|
@@ -9,13 +9,14 @@ export declare function localstorageKey(key: PublicKey): string;
|
|
|
9
9
|
* @param setStatus A global state updator. Set live status message showing on webpage
|
|
10
10
|
* @returns Array of decrypted UTXOs that belong to the user
|
|
11
11
|
*/
|
|
12
|
-
export declare function getUtxosSPL({ publicKey, connection, encryptionService, storage, mintAddress, abortSignal }: {
|
|
12
|
+
export declare function getUtxosSPL({ publicKey, connection, encryptionService, storage, mintAddress, abortSignal, offset }: {
|
|
13
13
|
publicKey: PublicKey;
|
|
14
14
|
connection: Connection;
|
|
15
15
|
encryptionService: EncryptionService;
|
|
16
16
|
storage: Storage;
|
|
17
17
|
mintAddress: PublicKey;
|
|
18
18
|
abortSignal?: AbortSignal;
|
|
19
|
+
offset?: number;
|
|
19
20
|
}): Promise<Utxo[]>;
|
|
20
21
|
/**
|
|
21
22
|
* Check if a UTXO has been spent
|
package/dist/getUtxosSPL.js
CHANGED
|
@@ -28,7 +28,7 @@ let decryptionTaskFinished = 0;
|
|
|
28
28
|
* @param setStatus A global state updator. Set live status message showing on webpage
|
|
29
29
|
* @returns Array of decrypted UTXOs that belong to the user
|
|
30
30
|
*/
|
|
31
|
-
export async function getUtxosSPL({ publicKey, connection, encryptionService, storage, mintAddress, abortSignal }) {
|
|
31
|
+
export async function getUtxosSPL({ publicKey, connection, encryptionService, storage, mintAddress, abortSignal, offset }) {
|
|
32
32
|
let valid_utxos = [];
|
|
33
33
|
let valid_strings = [];
|
|
34
34
|
let history_indexes = [];
|
|
@@ -43,15 +43,22 @@ export async function getUtxosSPL({ publicKey, connection, encryptionService, st
|
|
|
43
43
|
roundStartIndex = 0;
|
|
44
44
|
}
|
|
45
45
|
decryptionTaskFinished = 0;
|
|
46
|
+
if (!offset) {
|
|
47
|
+
offset = 0;
|
|
48
|
+
}
|
|
49
|
+
roundStartIndex = Math.max(offset, roundStartIndex);
|
|
46
50
|
while (true) {
|
|
47
51
|
if (abortSignal?.aborted) {
|
|
48
52
|
throw new Error('aborted');
|
|
49
53
|
}
|
|
50
54
|
let offsetStr = storage.getItem(LSK_FETCH_OFFSET + localstorageKey(publicKey_ata));
|
|
51
55
|
let fetch_utxo_offset = offsetStr ? Number(offsetStr) : 0;
|
|
56
|
+
if (offset) {
|
|
57
|
+
fetch_utxo_offset = Math.max(offset, fetch_utxo_offset);
|
|
58
|
+
}
|
|
52
59
|
let fetch_utxo_end = fetch_utxo_offset + FETCH_UTXOS_GROUP_SIZE;
|
|
53
60
|
let fetch_utxo_url = `${RELAYER_API_URL}/utxos/range?token=usdc&start=${fetch_utxo_offset}&end=${fetch_utxo_end}`;
|
|
54
|
-
let fetched = await fetchUserUtxos({ publicKey, connection, url: fetch_utxo_url, encryptionService, storage, publicKey_ata });
|
|
61
|
+
let fetched = await fetchUserUtxos({ publicKey, connection, url: fetch_utxo_url, encryptionService, storage, publicKey_ata, initOffset: offset });
|
|
55
62
|
let am = 0;
|
|
56
63
|
const nonZeroUtxos = [];
|
|
57
64
|
const nonZeroEncrypted = [];
|
|
@@ -109,7 +116,7 @@ export async function getUtxosSPL({ publicKey, connection, encryptionService, st
|
|
|
109
116
|
// reorgnize
|
|
110
117
|
return valid_utxos.filter(u => u.mintAddress == mintAddress.toString());
|
|
111
118
|
}
|
|
112
|
-
async function fetchUserUtxos({ publicKey, connection, url, storage, encryptionService, publicKey_ata }) {
|
|
119
|
+
async function fetchUserUtxos({ publicKey, connection, url, storage, encryptionService, publicKey_ata, initOffset }) {
|
|
113
120
|
const lightWasm = await WasmFactory.getInstance();
|
|
114
121
|
// Derive the UTXO keypair from the wallet keypair
|
|
115
122
|
const utxoPrivateKey = encryptionService.deriveUtxoPrivateKey();
|
|
@@ -3,7 +3,7 @@ import BN from 'bn.js';
|
|
|
3
3
|
export declare const FIELD_SIZE: BN;
|
|
4
4
|
export declare const PROGRAM_ID: PublicKey;
|
|
5
5
|
export declare const FEE_RECIPIENT: PublicKey;
|
|
6
|
-
export declare const FETCH_UTXOS_GROUP_SIZE =
|
|
6
|
+
export declare const FETCH_UTXOS_GROUP_SIZE = 20000;
|
|
7
7
|
export declare const TRANSACT_IX_DISCRIMINATOR: Buffer<ArrayBuffer>;
|
|
8
8
|
export declare const TRANSACT_SPL_IX_DISCRIMINATOR: Buffer<ArrayBuffer>;
|
|
9
9
|
export declare const MERKLE_TREE_DEPTH = 26;
|
package/dist/utils/constants.js
CHANGED
|
@@ -3,7 +3,7 @@ import BN from 'bn.js';
|
|
|
3
3
|
export const FIELD_SIZE = new BN('21888242871839275222246405745257275088548364400416034343698204186575808495617');
|
|
4
4
|
export const PROGRAM_ID = process.env.NEXT_PUBLIC_PROGRAM_ID ? new PublicKey(process.env.NEXT_PUBLIC_PROGRAM_ID) : new PublicKey('9fhQBbumKEFuXtMBDw8AaQyAjCorLGJQiS3skWZdQyQD');
|
|
5
5
|
export const FEE_RECIPIENT = new PublicKey('AWexibGxNFKTa1b5R5MN4PJr9HWnWRwf8EW9g8cLx3dM');
|
|
6
|
-
export const FETCH_UTXOS_GROUP_SIZE =
|
|
6
|
+
export const FETCH_UTXOS_GROUP_SIZE = 20_000;
|
|
7
7
|
export const TRANSACT_IX_DISCRIMINATOR = Buffer.from([217, 149, 130, 143, 221, 52, 252, 119]);
|
|
8
8
|
export const TRANSACT_SPL_IX_DISCRIMINATOR = Buffer.from([154, 66, 244, 204, 78, 225, 163, 151]);
|
|
9
9
|
export const MERKLE_TREE_DEPTH = 26;
|
package/package.json
CHANGED
package/src/getUtxos.ts
CHANGED
|
@@ -51,12 +51,13 @@ let decryptionTaskFinished = 0;
|
|
|
51
51
|
* @returns Array of decrypted UTXOs that belong to the user
|
|
52
52
|
*/
|
|
53
53
|
|
|
54
|
-
export async function getUtxos({ publicKey, connection, encryptionService, storage, abortSignal }: {
|
|
54
|
+
export async function getUtxos({ publicKey, connection, encryptionService, storage, abortSignal, offset }: {
|
|
55
55
|
publicKey: PublicKey,
|
|
56
56
|
connection: Connection,
|
|
57
57
|
encryptionService: EncryptionService,
|
|
58
58
|
storage: Storage,
|
|
59
59
|
abortSignal?: AbortSignal
|
|
60
|
+
offset?: number
|
|
60
61
|
}): Promise<Utxo[]> {
|
|
61
62
|
|
|
62
63
|
let valid_utxos: Utxo[] = []
|
|
@@ -69,15 +70,22 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
69
70
|
roundStartIndex = 0
|
|
70
71
|
}
|
|
71
72
|
decryptionTaskFinished = 0
|
|
73
|
+
if (!offset) {
|
|
74
|
+
offset = 0
|
|
75
|
+
}
|
|
76
|
+
roundStartIndex = Math.max(offset, roundStartIndex)
|
|
72
77
|
while (true) {
|
|
73
78
|
if (abortSignal?.aborted) {
|
|
74
79
|
throw new Error('aborted')
|
|
75
80
|
}
|
|
76
81
|
let offsetStr = storage.getItem(LSK_FETCH_OFFSET + localstorageKey(publicKey))
|
|
77
82
|
let fetch_utxo_offset = offsetStr ? Number(offsetStr) : 0
|
|
83
|
+
if (offset) {
|
|
84
|
+
fetch_utxo_offset = Math.max(offset, fetch_utxo_offset)
|
|
85
|
+
}
|
|
78
86
|
let fetch_utxo_end = fetch_utxo_offset + FETCH_UTXOS_GROUP_SIZE
|
|
79
87
|
let fetch_utxo_url = `${RELAYER_API_URL}/utxos/range?start=${fetch_utxo_offset}&end=${fetch_utxo_end}`
|
|
80
|
-
let fetched = await fetchUserUtxos({ publicKey, connection, url: fetch_utxo_url, encryptionService, storage })
|
|
88
|
+
let fetched = await fetchUserUtxos({ publicKey, connection, url: fetch_utxo_url, encryptionService, storage, initOffset: offset })
|
|
81
89
|
let am = 0
|
|
82
90
|
|
|
83
91
|
const nonZeroUtxos: Utxo[] = [];
|
|
@@ -131,12 +139,13 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
131
139
|
|
|
132
140
|
}
|
|
133
141
|
|
|
134
|
-
async function fetchUserUtxos({ publicKey, connection, url, storage, encryptionService }: {
|
|
142
|
+
async function fetchUserUtxos({ publicKey, connection, url, storage, encryptionService, initOffset }: {
|
|
135
143
|
publicKey: PublicKey,
|
|
136
144
|
connection: Connection,
|
|
137
145
|
url: string,
|
|
138
146
|
encryptionService: EncryptionService,
|
|
139
147
|
storage: Storage
|
|
148
|
+
initOffset: number
|
|
140
149
|
}): Promise<{
|
|
141
150
|
encryptedOutputs: string[],
|
|
142
151
|
utxos: Utxo[],
|
|
@@ -188,6 +197,7 @@ async function fetchUserUtxos({ publicKey, connection, url, storage, encryptionS
|
|
|
188
197
|
|
|
189
198
|
|
|
190
199
|
let decryptionTaskTotal = data.total + cachedStringNum - roundStartIndex;
|
|
200
|
+
|
|
191
201
|
let batchRes = await decrypt_outputs(encryptedOutputs, encryptionService, utxoKeypair, lightWasm)
|
|
192
202
|
decryptionTaskFinished += encryptedOutputs.length
|
|
193
203
|
logger.debug('batchReslen', batchRes.length)
|
package/src/getUtxosSPL.ts
CHANGED
|
@@ -55,13 +55,14 @@ let decryptionTaskFinished = 0;
|
|
|
55
55
|
* @returns Array of decrypted UTXOs that belong to the user
|
|
56
56
|
*/
|
|
57
57
|
|
|
58
|
-
export async function getUtxosSPL({ publicKey, connection, encryptionService, storage, mintAddress, abortSignal }: {
|
|
58
|
+
export async function getUtxosSPL({ publicKey, connection, encryptionService, storage, mintAddress, abortSignal, offset }: {
|
|
59
59
|
publicKey: PublicKey,
|
|
60
60
|
connection: Connection,
|
|
61
61
|
encryptionService: EncryptionService,
|
|
62
62
|
storage: Storage,
|
|
63
63
|
mintAddress: PublicKey,
|
|
64
64
|
abortSignal?: AbortSignal
|
|
65
|
+
offset?: number
|
|
65
66
|
}): Promise<Utxo[]> {
|
|
66
67
|
let valid_utxos: Utxo[] = []
|
|
67
68
|
let valid_strings: string[] = []
|
|
@@ -79,15 +80,22 @@ export async function getUtxosSPL({ publicKey, connection, encryptionService, st
|
|
|
79
80
|
roundStartIndex = 0
|
|
80
81
|
}
|
|
81
82
|
decryptionTaskFinished = 0
|
|
83
|
+
if (!offset) {
|
|
84
|
+
offset = 0
|
|
85
|
+
}
|
|
86
|
+
roundStartIndex = Math.max(offset, roundStartIndex)
|
|
82
87
|
while (true) {
|
|
83
88
|
if (abortSignal?.aborted) {
|
|
84
89
|
throw new Error('aborted')
|
|
85
90
|
}
|
|
86
91
|
let offsetStr = storage.getItem(LSK_FETCH_OFFSET + localstorageKey(publicKey_ata))
|
|
87
92
|
let fetch_utxo_offset = offsetStr ? Number(offsetStr) : 0
|
|
93
|
+
if (offset) {
|
|
94
|
+
fetch_utxo_offset = Math.max(offset, fetch_utxo_offset)
|
|
95
|
+
}
|
|
88
96
|
let fetch_utxo_end = fetch_utxo_offset + FETCH_UTXOS_GROUP_SIZE
|
|
89
97
|
let fetch_utxo_url = `${RELAYER_API_URL}/utxos/range?token=usdc&start=${fetch_utxo_offset}&end=${fetch_utxo_end}`
|
|
90
|
-
let fetched = await fetchUserUtxos({ publicKey, connection, url: fetch_utxo_url, encryptionService, storage, publicKey_ata })
|
|
98
|
+
let fetched = await fetchUserUtxos({ publicKey, connection, url: fetch_utxo_url, encryptionService, storage, publicKey_ata, initOffset: offset })
|
|
91
99
|
let am = 0
|
|
92
100
|
|
|
93
101
|
const nonZeroUtxos: Utxo[] = [];
|
|
@@ -145,13 +153,14 @@ export async function getUtxosSPL({ publicKey, connection, encryptionService, st
|
|
|
145
153
|
return valid_utxos.filter(u => u.mintAddress == mintAddress.toString())
|
|
146
154
|
}
|
|
147
155
|
|
|
148
|
-
async function fetchUserUtxos({ publicKey, connection, url, storage, encryptionService, publicKey_ata }: {
|
|
156
|
+
async function fetchUserUtxos({ publicKey, connection, url, storage, encryptionService, publicKey_ata, initOffset }: {
|
|
149
157
|
publicKey: PublicKey,
|
|
150
158
|
connection: Connection,
|
|
151
159
|
url: string,
|
|
152
160
|
encryptionService: EncryptionService,
|
|
153
161
|
storage: Storage,
|
|
154
162
|
publicKey_ata: PublicKey
|
|
163
|
+
initOffset: number
|
|
155
164
|
}): Promise<{
|
|
156
165
|
encryptedOutputs: string[],
|
|
157
166
|
utxos: Utxo[],
|
package/src/utils/constants.ts
CHANGED
|
@@ -7,7 +7,7 @@ export const PROGRAM_ID = process.env.NEXT_PUBLIC_PROGRAM_ID ? new PublicKey(pro
|
|
|
7
7
|
|
|
8
8
|
export const FEE_RECIPIENT = new PublicKey('AWexibGxNFKTa1b5R5MN4PJr9HWnWRwf8EW9g8cLx3dM')
|
|
9
9
|
|
|
10
|
-
export const FETCH_UTXOS_GROUP_SIZE =
|
|
10
|
+
export const FETCH_UTXOS_GROUP_SIZE = 20_000
|
|
11
11
|
|
|
12
12
|
export const TRANSACT_IX_DISCRIMINATOR = Buffer.from([217, 149, 130, 143, 221, 52, 252, 119]);
|
|
13
13
|
|