@textrp/briij-js-sdk 42.0.0 → 43.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +7 -4
  2. package/README.md +71 -0
  3. package/lib/@types/auth.d.ts +57 -2
  4. package/lib/@types/auth.d.ts.map +1 -1
  5. package/lib/@types/auth.js +2 -0
  6. package/lib/@types/auth.js.map +1 -1
  7. package/lib/@types/event.d.ts +3 -0
  8. package/lib/@types/event.d.ts.map +1 -1
  9. package/lib/@types/event.js.map +1 -1
  10. package/lib/@types/synapse.d.ts +64 -0
  11. package/lib/@types/synapse.d.ts.map +1 -1
  12. package/lib/@types/synapse.js.map +1 -1
  13. package/lib/briij.d.ts +2 -0
  14. package/lib/briij.d.ts.map +1 -1
  15. package/lib/briij.js +2 -0
  16. package/lib/briij.js.map +1 -1
  17. package/lib/client.d.ts +100 -7
  18. package/lib/client.d.ts.map +1 -1
  19. package/lib/client.js +469 -213
  20. package/lib/client.js.map +1 -1
  21. package/lib/wallet-recovery.d.ts +24 -0
  22. package/lib/wallet-recovery.d.ts.map +1 -0
  23. package/lib/wallet-recovery.js +256 -0
  24. package/lib/wallet-recovery.js.map +1 -0
  25. package/lib/xrpl/identity.d.ts +2 -1
  26. package/lib/xrpl/identity.d.ts.map +1 -1
  27. package/lib/xrpl/identity.js +70 -47
  28. package/lib/xrpl/identity.js.map +1 -1
  29. package/lib/xrpl/trust.d.ts +4 -2
  30. package/lib/xrpl/trust.d.ts.map +1 -1
  31. package/lib/xrpl/trust.js +31 -19
  32. package/lib/xrpl/trust.js.map +1 -1
  33. package/lib/xrpl/verification.js +17 -6
  34. package/lib/xrpl/verification.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/@types/auth.ts +61 -2
  37. package/src/@types/event.ts +3 -0
  38. package/src/@types/synapse.ts +77 -0
  39. package/src/briij.ts +2 -0
  40. package/src/client.ts +344 -46
  41. package/src/wallet-recovery.ts +327 -0
  42. package/src/xrpl/identity.ts +66 -39
  43. package/src/xrpl/trust.ts +35 -18
  44. package/src/xrpl/verification.ts +19 -6
@@ -0,0 +1,24 @@
1
+ import { type WalletE2eeRecoveryEnvelope } from "./@types/auth.ts";
2
+ export interface CreateDualWrapEnvelopeParams {
3
+ chainId: string;
4
+ accountId: string;
5
+ backupPassword: string;
6
+ walletWrapKey: Uint8Array;
7
+ createdAtMs?: number;
8
+ keyId?: string;
9
+ recoveryKey?: Uint8Array;
10
+ }
11
+ export interface UnwrapWithWalletParams {
12
+ envelope: WalletE2eeRecoveryEnvelope;
13
+ walletWrapKey: Uint8Array;
14
+ }
15
+ export interface UnwrapWithPasswordParams {
16
+ envelope: WalletE2eeRecoveryEnvelope;
17
+ backupPassword: string;
18
+ }
19
+ export declare function deriveWalletWrapKeyFromSecret(walletSecret: string, chainId: string, accountId: string, homeserver: string): Promise<Uint8Array>;
20
+ export declare function validateRecoveryEnvelopeShape(value: unknown): asserts value is WalletE2eeRecoveryEnvelope;
21
+ export declare function createDualWrapEnvelope(params: CreateDualWrapEnvelopeParams): Promise<WalletE2eeRecoveryEnvelope>;
22
+ export declare function unwrapWithWallet({ envelope, walletWrapKey }: UnwrapWithWalletParams): Promise<Uint8Array>;
23
+ export declare function unwrapWithPassword({ envelope, backupPassword }: UnwrapWithPasswordParams): Promise<Uint8Array>;
24
+ //# sourceMappingURL=wallet-recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-recovery.d.ts","sourceRoot":"","sources":["../src/wallet-recovery.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,0BAA0B,EAA2B,MAAM,kBAAkB,CAAC;AAW5F,MAAM,WAAW,4BAA4B;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,UAAU,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,UAAU,CAAC;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACnC,QAAQ,EAAE,0BAA0B,CAAC;IACrC,aAAa,EAAE,UAAU,CAAC;CAC7B;AAED,MAAM,WAAW,wBAAwB;IACrC,QAAQ,EAAE,0BAA0B,CAAC;IACrC,cAAc,EAAE,MAAM,CAAC;CAC1B;AAgID,wBAAsB,6BAA6B,CAC/C,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACnB,OAAO,CAAC,UAAU,CAAC,CAQrB;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,0BAA0B,CAuEzG;AAED,wBAAsB,sBAAsB,CACxC,MAAM,EAAE,4BAA4B,GACrC,OAAO,CAAC,0BAA0B,CAAC,CAwCrC;AAED,wBAAsB,gBAAgB,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,sBAAsB,GAAG,OAAO,CAAC,UAAU,CAAC,CAG/G;AAED,wBAAsB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,wBAAwB,GAAG,OAAO,CAAC,UAAU,CAAC,CAKpH"}
@@ -0,0 +1,256 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ /*
3
+ Copyright 2026 TextRP
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */
17
+
18
+ var ENVELOPE_VERSION = 1;
19
+ var KEY_BYTES = 32;
20
+ var NONCE_BYTES = 12;
21
+ var SALT_BYTES = 16;
22
+ var PASSWORD_KDF_ITERATIONS = 210000;
23
+ var SUPPORTED_WRAP_ALG = "aes-256-gcm";
24
+ var SUPPORTED_WALLET_WRAP_KDF = "sha256-context-v1";
25
+ var SUPPORTED_PASSWORD_WRAP_KDF = "pbkdf2-sha256-v1";
26
+ function assert(condition, message) {
27
+ if (!condition) throw new Error(message);
28
+ }
29
+ function toBase64(bytes) {
30
+ if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
31
+ var binary = "";
32
+ bytes.forEach(b => binary += String.fromCodePoint(b));
33
+ return btoa(binary);
34
+ }
35
+ function fromBase64(value) {
36
+ if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(value, "base64"));
37
+ var binary = atob(value);
38
+ var out = new Uint8Array(binary.length);
39
+ for (var i = 0; i < binary.length; i++) out[i] = binary.codePointAt(i);
40
+ return out;
41
+ }
42
+ function toUtf8(value) {
43
+ return new TextEncoder().encode(value);
44
+ }
45
+ function toArrayBuffer(value) {
46
+ return value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength);
47
+ }
48
+ function randomBytes(len) {
49
+ var out = new Uint8Array(len);
50
+ globalThis.crypto.getRandomValues(out);
51
+ return out;
52
+ }
53
+ function importAesGcmKey(_x) {
54
+ return _importAesGcmKey.apply(this, arguments);
55
+ }
56
+ function _importAesGcmKey() {
57
+ _importAesGcmKey = _asyncToGenerator(function* (key) {
58
+ return yield globalThis.crypto.subtle.importKey("raw", toArrayBuffer(key), {
59
+ name: "AES-GCM"
60
+ }, false, ["encrypt", "decrypt"]);
61
+ });
62
+ return _importAesGcmKey.apply(this, arguments);
63
+ }
64
+ function encryptWrap(_x2, _x3) {
65
+ return _encryptWrap.apply(this, arguments);
66
+ }
67
+ function _encryptWrap() {
68
+ _encryptWrap = _asyncToGenerator(function* (plaintext, _ref) {
69
+ var {
70
+ key,
71
+ aad,
72
+ kdf,
73
+ params
74
+ } = _ref;
75
+ assert(key.length >= KEY_BYTES, "wallet recovery key must be at least 32 bytes");
76
+ var salt = randomBytes(SALT_BYTES);
77
+ var nonce = randomBytes(NONCE_BYTES);
78
+ var cryptoKey = yield importAesGcmKey(key.slice(0, KEY_BYTES));
79
+ var ciphertext = yield globalThis.crypto.subtle.encrypt({
80
+ name: "AES-GCM",
81
+ iv: toArrayBuffer(nonce),
82
+ additionalData: toArrayBuffer(aad),
83
+ tagLength: 128
84
+ }, cryptoKey, toArrayBuffer(plaintext));
85
+ return {
86
+ alg: "aes-256-gcm",
87
+ kdf,
88
+ salt: toBase64(salt),
89
+ nonce: toBase64(nonce),
90
+ ciphertext: toBase64(new Uint8Array(ciphertext)),
91
+ aad: toBase64(aad),
92
+ params
93
+ };
94
+ });
95
+ return _encryptWrap.apply(this, arguments);
96
+ }
97
+ function decryptWrap(_x4, _x5) {
98
+ return _decryptWrap.apply(this, arguments);
99
+ }
100
+ function _decryptWrap() {
101
+ _decryptWrap = _asyncToGenerator(function* (wrap, key) {
102
+ assert(wrap.alg === SUPPORTED_WRAP_ALG, "Unsupported recovery wrap alg '".concat(wrap.alg, "', expected '").concat(SUPPORTED_WRAP_ALG, "'"));
103
+ assert(wrap.kdf === SUPPORTED_WALLET_WRAP_KDF || wrap.kdf === SUPPORTED_PASSWORD_WRAP_KDF, "Unsupported recovery wrap kdf '".concat(wrap.kdf, "'"));
104
+ var nonce = fromBase64(wrap.nonce);
105
+ var aad = wrap.aad ? fromBase64(wrap.aad) : new Uint8Array();
106
+ var ciphertext = fromBase64(wrap.ciphertext);
107
+ var cryptoKey = yield importAesGcmKey(key.slice(0, KEY_BYTES));
108
+ var plaintext = yield globalThis.crypto.subtle.decrypt({
109
+ name: "AES-GCM",
110
+ iv: toArrayBuffer(nonce),
111
+ additionalData: toArrayBuffer(aad),
112
+ tagLength: 128
113
+ }, cryptoKey, toArrayBuffer(ciphertext));
114
+ return new Uint8Array(plaintext);
115
+ });
116
+ return _decryptWrap.apply(this, arguments);
117
+ }
118
+ function derivePasswordWrapKey(_x6, _x7) {
119
+ return _derivePasswordWrapKey.apply(this, arguments);
120
+ }
121
+ function _derivePasswordWrapKey() {
122
+ _derivePasswordWrapKey = _asyncToGenerator(function* (password, salt) {
123
+ var keyMaterial = yield globalThis.crypto.subtle.importKey("raw", toArrayBuffer(toUtf8(password)), "PBKDF2", false, ["deriveBits"]);
124
+ var bits = yield globalThis.crypto.subtle.deriveBits({
125
+ name: "PBKDF2",
126
+ hash: "SHA-256",
127
+ salt: toArrayBuffer(salt),
128
+ iterations: PASSWORD_KDF_ITERATIONS
129
+ }, keyMaterial, KEY_BYTES * 8);
130
+ return new Uint8Array(bits);
131
+ });
132
+ return _derivePasswordWrapKey.apply(this, arguments);
133
+ }
134
+ export function deriveWalletWrapKeyFromSecret(_x8, _x9, _x0, _x1) {
135
+ return _deriveWalletWrapKeyFromSecret.apply(this, arguments);
136
+ }
137
+ function _deriveWalletWrapKeyFromSecret() {
138
+ _deriveWalletWrapKeyFromSecret = _asyncToGenerator(function* (walletSecret, chainId, accountId, homeserver) {
139
+ var canonicalHomeserver = canonicalizeHomeserver(homeserver);
140
+ var context = "briij-wallet-auth-wrap-v1:".concat(canonicalHomeserver, ":").concat(chainId, ":").concat(accountId);
141
+ var digest = yield globalThis.crypto.subtle.digest("SHA-256", toArrayBuffer(toUtf8("".concat(context, ":").concat(walletSecret))));
142
+ return new Uint8Array(digest);
143
+ });
144
+ return _deriveWalletWrapKeyFromSecret.apply(this, arguments);
145
+ }
146
+ export function validateRecoveryEnvelopeShape(value) {
147
+ assert(!!value && typeof value === "object", "recovery envelope must be an object");
148
+ var envelope = value;
149
+ assert(typeof envelope.envelope_version === "number", "envelope_version must be a number");
150
+ assert(envelope.envelope_version === ENVELOPE_VERSION, "Unsupported envelope_version '".concat(envelope.envelope_version, "', expected '").concat(ENVELOPE_VERSION, "'"));
151
+ assert(typeof envelope.chain_id === "string" && envelope.chain_id.length > 0, "chain_id is required");
152
+ assert(typeof envelope.account_id === "string" && envelope.account_id.length > 0, "account_id is required");
153
+ assert(typeof envelope.created_at_ms === "number", "created_at_ms must be a number");
154
+ assert(typeof envelope.key_id === "string" && envelope.key_id.length > 0, "key_id is required");
155
+ assert(!!envelope.wallet_wrap && typeof envelope.wallet_wrap === "object", "wallet_wrap is required");
156
+ assert(!!envelope.password_wrap && typeof envelope.password_wrap === "object", "password_wrap is required");
157
+ assert(typeof envelope.wallet_wrap.alg === "string" && envelope.wallet_wrap.alg.length > 0, "wallet_wrap.alg is required");
158
+ assert(typeof envelope.wallet_wrap.kdf === "string" && envelope.wallet_wrap.kdf.length > 0, "wallet_wrap.kdf is required");
159
+ assert(envelope.wallet_wrap.alg === SUPPORTED_WRAP_ALG, "Unsupported wallet_wrap.alg '".concat(envelope.wallet_wrap.alg, "', expected '").concat(SUPPORTED_WRAP_ALG, "'"));
160
+ assert(envelope.wallet_wrap.kdf === SUPPORTED_WALLET_WRAP_KDF, "Unsupported wallet_wrap.kdf '".concat(envelope.wallet_wrap.kdf, "', expected '").concat(SUPPORTED_WALLET_WRAP_KDF, "'"));
161
+ assert(typeof envelope.wallet_wrap.salt === "string" && envelope.wallet_wrap.salt.length > 0, "wallet_wrap.salt is required");
162
+ assert(typeof envelope.wallet_wrap.nonce === "string" && envelope.wallet_wrap.nonce.length > 0, "wallet_wrap.nonce is required");
163
+ assert(typeof envelope.wallet_wrap.ciphertext === "string" && envelope.wallet_wrap.ciphertext.length > 0, "wallet_wrap.ciphertext is required");
164
+ assert(typeof envelope.password_wrap.alg === "string" && envelope.password_wrap.alg.length > 0, "password_wrap.alg is required");
165
+ assert(typeof envelope.password_wrap.kdf === "string" && envelope.password_wrap.kdf.length > 0, "password_wrap.kdf is required");
166
+ assert(envelope.password_wrap.alg === SUPPORTED_WRAP_ALG, "Unsupported password_wrap.alg '".concat(envelope.password_wrap.alg, "', expected '").concat(SUPPORTED_WRAP_ALG, "'"));
167
+ assert(envelope.password_wrap.kdf === SUPPORTED_PASSWORD_WRAP_KDF, "Unsupported password_wrap.kdf '".concat(envelope.password_wrap.kdf, "', expected '").concat(SUPPORTED_PASSWORD_WRAP_KDF, "'"));
168
+ assert(typeof envelope.password_wrap.salt === "string" && envelope.password_wrap.salt.length > 0, "password_wrap.salt is required");
169
+ assert(typeof envelope.password_wrap.nonce === "string" && envelope.password_wrap.nonce.length > 0, "password_wrap.nonce is required");
170
+ assert(typeof envelope.password_wrap.ciphertext === "string" && envelope.password_wrap.ciphertext.length > 0, "password_wrap.ciphertext is required");
171
+ }
172
+ export function createDualWrapEnvelope(_x10) {
173
+ return _createDualWrapEnvelope.apply(this, arguments);
174
+ }
175
+ function _createDualWrapEnvelope() {
176
+ _createDualWrapEnvelope = _asyncToGenerator(function* (params) {
177
+ var _params$createdAtMs, _params$keyId, _params$recoveryKey;
178
+ assert(params.chainId.length > 0, "chainId is required");
179
+ assert(params.accountId.length > 0, "accountId is required");
180
+ assert(params.backupPassword.length > 0, "backupPassword is required");
181
+ assert(params.walletWrapKey.length >= KEY_BYTES, "walletWrapKey must be at least 32 bytes");
182
+ var createdAtMs = (_params$createdAtMs = params.createdAtMs) !== null && _params$createdAtMs !== void 0 ? _params$createdAtMs : Date.now();
183
+ var keyId = (_params$keyId = params.keyId) !== null && _params$keyId !== void 0 ? _params$keyId : "k-".concat(toBase64(randomBytes(8)).replace(/=+$/g, ""));
184
+ var recoveryKey = (_params$recoveryKey = params.recoveryKey) !== null && _params$recoveryKey !== void 0 ? _params$recoveryKey : randomBytes(KEY_BYTES);
185
+ assert(recoveryKey.length === KEY_BYTES, "recoveryKey must be 32 bytes");
186
+ var aad = toUtf8("briij-recovery-envelope-v1:".concat(params.chainId, ":").concat(params.accountId, ":").concat(keyId, ":").concat(createdAtMs));
187
+ var walletWrap = yield encryptWrap(recoveryKey, {
188
+ key: params.walletWrapKey,
189
+ aad,
190
+ kdf: "sha256-context-v1"
191
+ });
192
+ var passwordSalt = randomBytes(SALT_BYTES);
193
+ var passwordWrapKey = yield derivePasswordWrapKey(params.backupPassword, passwordSalt);
194
+ var passwordWrap = yield encryptWrap(recoveryKey, {
195
+ key: passwordWrapKey,
196
+ aad,
197
+ kdf: "pbkdf2-sha256-v1",
198
+ params: {
199
+ iterations: PASSWORD_KDF_ITERATIONS,
200
+ hash: "SHA-256"
201
+ }
202
+ });
203
+ passwordWrap.salt = toBase64(passwordSalt);
204
+ return {
205
+ envelope_version: ENVELOPE_VERSION,
206
+ chain_id: params.chainId,
207
+ account_id: params.accountId,
208
+ created_at_ms: createdAtMs,
209
+ key_id: keyId,
210
+ wallet_wrap: walletWrap,
211
+ password_wrap: passwordWrap
212
+ };
213
+ });
214
+ return _createDualWrapEnvelope.apply(this, arguments);
215
+ }
216
+ export function unwrapWithWallet(_x11) {
217
+ return _unwrapWithWallet.apply(this, arguments);
218
+ }
219
+ function _unwrapWithWallet() {
220
+ _unwrapWithWallet = _asyncToGenerator(function* (_ref2) {
221
+ var {
222
+ envelope,
223
+ walletWrapKey
224
+ } = _ref2;
225
+ validateRecoveryEnvelopeShape(envelope);
226
+ return yield decryptWrap(envelope.wallet_wrap, walletWrapKey);
227
+ });
228
+ return _unwrapWithWallet.apply(this, arguments);
229
+ }
230
+ export function unwrapWithPassword(_x12) {
231
+ return _unwrapWithPassword.apply(this, arguments);
232
+ }
233
+ function _unwrapWithPassword() {
234
+ _unwrapWithPassword = _asyncToGenerator(function* (_ref3) {
235
+ var {
236
+ envelope,
237
+ backupPassword
238
+ } = _ref3;
239
+ validateRecoveryEnvelopeShape(envelope);
240
+ var passwordSalt = fromBase64(envelope.password_wrap.salt);
241
+ var passwordWrapKey = yield derivePasswordWrapKey(backupPassword, passwordSalt);
242
+ return yield decryptWrap(envelope.password_wrap, passwordWrapKey);
243
+ });
244
+ return _unwrapWithPassword.apply(this, arguments);
245
+ }
246
+ function canonicalizeHomeserver(homeserver) {
247
+ var trimmed = homeserver.trim().replace(/\/+$/, "");
248
+ try {
249
+ var parsed = new URL(trimmed);
250
+ parsed.hostname = parsed.hostname.toLowerCase();
251
+ return parsed.toString().replace(/\/+$/, "");
252
+ } catch (_unused) {
253
+ return trimmed.toLowerCase();
254
+ }
255
+ }
256
+ //# sourceMappingURL=wallet-recovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-recovery.js","names":["ENVELOPE_VERSION","KEY_BYTES","NONCE_BYTES","SALT_BYTES","PASSWORD_KDF_ITERATIONS","SUPPORTED_WRAP_ALG","SUPPORTED_WALLET_WRAP_KDF","SUPPORTED_PASSWORD_WRAP_KDF","assert","condition","message","Error","toBase64","bytes","Buffer","from","toString","binary","forEach","b","String","fromCodePoint","btoa","fromBase64","value","Uint8Array","atob","out","length","i","codePointAt","toUtf8","TextEncoder","encode","toArrayBuffer","buffer","slice","byteOffset","byteLength","randomBytes","len","globalThis","crypto","getRandomValues","importAesGcmKey","_x","_importAesGcmKey","apply","arguments","_asyncToGenerator","key","subtle","importKey","name","encryptWrap","_x2","_x3","_encryptWrap","plaintext","_ref","aad","kdf","params","salt","nonce","cryptoKey","ciphertext","encrypt","iv","additionalData","tagLength","alg","decryptWrap","_x4","_x5","_decryptWrap","wrap","concat","decrypt","derivePasswordWrapKey","_x6","_x7","_derivePasswordWrapKey","password","keyMaterial","bits","deriveBits","hash","iterations","deriveWalletWrapKeyFromSecret","_x8","_x9","_x0","_x1","_deriveWalletWrapKeyFromSecret","walletSecret","chainId","accountId","homeserver","canonicalHomeserver","canonicalizeHomeserver","context","digest","validateRecoveryEnvelopeShape","envelope","envelope_version","chain_id","account_id","created_at_ms","key_id","wallet_wrap","password_wrap","createDualWrapEnvelope","_x10","_createDualWrapEnvelope","_params$createdAtMs","_params$keyId","_params$recoveryKey","backupPassword","walletWrapKey","createdAtMs","Date","now","keyId","replace","recoveryKey","walletWrap","passwordSalt","passwordWrapKey","passwordWrap","unwrapWithWallet","_x11","_unwrapWithWallet","_ref2","unwrapWithPassword","_x12","_unwrapWithPassword","_ref3","trimmed","trim","parsed","URL","hostname","toLowerCase","_unused"],"sources":["../src/wallet-recovery.ts"],"sourcesContent":["/*\nCopyright 2026 TextRP\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type WalletE2eeRecoveryEnvelope, type WalletRecoveryWrap } from \"./@types/auth.ts\";\n\nconst ENVELOPE_VERSION = 1;\nconst KEY_BYTES = 32;\nconst NONCE_BYTES = 12;\nconst SALT_BYTES = 16;\nconst PASSWORD_KDF_ITERATIONS = 210_000;\nconst SUPPORTED_WRAP_ALG = \"aes-256-gcm\";\nconst SUPPORTED_WALLET_WRAP_KDF = \"sha256-context-v1\";\nconst SUPPORTED_PASSWORD_WRAP_KDF = \"pbkdf2-sha256-v1\";\n\nexport interface CreateDualWrapEnvelopeParams {\n chainId: string;\n accountId: string;\n backupPassword: string;\n walletWrapKey: Uint8Array;\n createdAtMs?: number;\n keyId?: string;\n recoveryKey?: Uint8Array;\n}\n\nexport interface UnwrapWithWalletParams {\n envelope: WalletE2eeRecoveryEnvelope;\n walletWrapKey: Uint8Array;\n}\n\nexport interface UnwrapWithPasswordParams {\n envelope: WalletE2eeRecoveryEnvelope;\n backupPassword: string;\n}\n\nfunction assert(condition: boolean, message: string): asserts condition {\n if (!condition) throw new Error(message);\n}\n\nfunction toBase64(bytes: Uint8Array): string {\n if (typeof Buffer !== \"undefined\") return Buffer.from(bytes).toString(\"base64\");\n let binary = \"\";\n bytes.forEach((b) => (binary += String.fromCodePoint(b)));\n return btoa(binary);\n}\n\nfunction fromBase64(value: string): Uint8Array {\n if (typeof Buffer !== \"undefined\") return new Uint8Array(Buffer.from(value, \"base64\"));\n const binary = atob(value);\n const out = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) out[i] = binary.codePointAt(i)!;\n return out;\n}\n\nfunction toUtf8(value: string): Uint8Array {\n return new TextEncoder().encode(value);\n}\n\nfunction toArrayBuffer(value: Uint8Array): ArrayBuffer {\n return value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength) as ArrayBuffer;\n}\n\nfunction randomBytes(len: number): Uint8Array {\n const out = new Uint8Array(len);\n globalThis.crypto.getRandomValues(out);\n return out;\n}\n\nasync function importAesGcmKey(key: Uint8Array): Promise<CryptoKey> {\n return await globalThis.crypto.subtle.importKey(\"raw\", toArrayBuffer(key), { name: \"AES-GCM\" }, false, [\n \"encrypt\",\n \"decrypt\",\n ]);\n}\n\nasync function encryptWrap(\n plaintext: Uint8Array,\n {\n key,\n aad,\n kdf,\n params,\n }: {\n key: Uint8Array;\n aad: Uint8Array;\n kdf: string;\n params?: Record<string, unknown>;\n },\n): Promise<WalletRecoveryWrap> {\n assert(key.length >= KEY_BYTES, \"wallet recovery key must be at least 32 bytes\");\n const salt = randomBytes(SALT_BYTES);\n const nonce = randomBytes(NONCE_BYTES);\n const cryptoKey = await importAesGcmKey(key.slice(0, KEY_BYTES));\n const ciphertext = await globalThis.crypto.subtle.encrypt(\n {\n name: \"AES-GCM\",\n iv: toArrayBuffer(nonce),\n additionalData: toArrayBuffer(aad),\n tagLength: 128,\n },\n cryptoKey,\n toArrayBuffer(plaintext),\n );\n return {\n alg: \"aes-256-gcm\",\n kdf,\n salt: toBase64(salt),\n nonce: toBase64(nonce),\n ciphertext: toBase64(new Uint8Array(ciphertext)),\n aad: toBase64(aad),\n params,\n };\n}\n\nasync function decryptWrap(wrap: WalletRecoveryWrap, key: Uint8Array): Promise<Uint8Array> {\n assert(\n wrap.alg === SUPPORTED_WRAP_ALG,\n `Unsupported recovery wrap alg '${wrap.alg}', expected '${SUPPORTED_WRAP_ALG}'`,\n );\n assert(\n wrap.kdf === SUPPORTED_WALLET_WRAP_KDF || wrap.kdf === SUPPORTED_PASSWORD_WRAP_KDF,\n `Unsupported recovery wrap kdf '${wrap.kdf}'`,\n );\n const nonce = fromBase64(wrap.nonce);\n const aad = wrap.aad ? fromBase64(wrap.aad) : new Uint8Array();\n const ciphertext = fromBase64(wrap.ciphertext);\n const cryptoKey = await importAesGcmKey(key.slice(0, KEY_BYTES));\n const plaintext = await globalThis.crypto.subtle.decrypt(\n {\n name: \"AES-GCM\",\n iv: toArrayBuffer(nonce),\n additionalData: toArrayBuffer(aad),\n tagLength: 128,\n },\n cryptoKey,\n toArrayBuffer(ciphertext),\n );\n return new Uint8Array(plaintext);\n}\n\nasync function derivePasswordWrapKey(password: string, salt: Uint8Array): Promise<Uint8Array> {\n const keyMaterial = await globalThis.crypto.subtle.importKey(\n \"raw\",\n toArrayBuffer(toUtf8(password)),\n \"PBKDF2\",\n false,\n [\"deriveBits\"],\n );\n const bits = await globalThis.crypto.subtle.deriveBits(\n {\n name: \"PBKDF2\",\n hash: \"SHA-256\",\n salt: toArrayBuffer(salt),\n iterations: PASSWORD_KDF_ITERATIONS,\n },\n keyMaterial,\n KEY_BYTES * 8,\n );\n return new Uint8Array(bits);\n}\n\nexport async function deriveWalletWrapKeyFromSecret(\n walletSecret: string,\n chainId: string,\n accountId: string,\n homeserver: string,\n): Promise<Uint8Array> {\n const canonicalHomeserver = canonicalizeHomeserver(homeserver);\n const context = `briij-wallet-auth-wrap-v1:${canonicalHomeserver}:${chainId}:${accountId}`;\n const digest = await globalThis.crypto.subtle.digest(\n \"SHA-256\",\n toArrayBuffer(toUtf8(`${context}:${walletSecret}`)),\n );\n return new Uint8Array(digest);\n}\n\nexport function validateRecoveryEnvelopeShape(value: unknown): asserts value is WalletE2eeRecoveryEnvelope {\n assert(!!value && typeof value === \"object\", \"recovery envelope must be an object\");\n const envelope = value as WalletE2eeRecoveryEnvelope;\n assert(typeof envelope.envelope_version === \"number\", \"envelope_version must be a number\");\n assert(\n envelope.envelope_version === ENVELOPE_VERSION,\n `Unsupported envelope_version '${envelope.envelope_version}', expected '${ENVELOPE_VERSION}'`,\n );\n assert(typeof envelope.chain_id === \"string\" && envelope.chain_id.length > 0, \"chain_id is required\");\n assert(typeof envelope.account_id === \"string\" && envelope.account_id.length > 0, \"account_id is required\");\n assert(typeof envelope.created_at_ms === \"number\", \"created_at_ms must be a number\");\n assert(typeof envelope.key_id === \"string\" && envelope.key_id.length > 0, \"key_id is required\");\n assert(!!envelope.wallet_wrap && typeof envelope.wallet_wrap === \"object\", \"wallet_wrap is required\");\n assert(!!envelope.password_wrap && typeof envelope.password_wrap === \"object\", \"password_wrap is required\");\n assert(\n typeof envelope.wallet_wrap.alg === \"string\" && envelope.wallet_wrap.alg.length > 0,\n \"wallet_wrap.alg is required\",\n );\n assert(\n typeof envelope.wallet_wrap.kdf === \"string\" && envelope.wallet_wrap.kdf.length > 0,\n \"wallet_wrap.kdf is required\",\n );\n assert(\n envelope.wallet_wrap.alg === SUPPORTED_WRAP_ALG,\n `Unsupported wallet_wrap.alg '${envelope.wallet_wrap.alg}', expected '${SUPPORTED_WRAP_ALG}'`,\n );\n assert(\n envelope.wallet_wrap.kdf === SUPPORTED_WALLET_WRAP_KDF,\n `Unsupported wallet_wrap.kdf '${envelope.wallet_wrap.kdf}', expected '${SUPPORTED_WALLET_WRAP_KDF}'`,\n );\n assert(\n typeof envelope.wallet_wrap.salt === \"string\" && envelope.wallet_wrap.salt.length > 0,\n \"wallet_wrap.salt is required\",\n );\n assert(\n typeof envelope.wallet_wrap.nonce === \"string\" && envelope.wallet_wrap.nonce.length > 0,\n \"wallet_wrap.nonce is required\",\n );\n assert(\n typeof envelope.wallet_wrap.ciphertext === \"string\" && envelope.wallet_wrap.ciphertext.length > 0,\n \"wallet_wrap.ciphertext is required\",\n );\n\n assert(\n typeof envelope.password_wrap.alg === \"string\" && envelope.password_wrap.alg.length > 0,\n \"password_wrap.alg is required\",\n );\n assert(\n typeof envelope.password_wrap.kdf === \"string\" && envelope.password_wrap.kdf.length > 0,\n \"password_wrap.kdf is required\",\n );\n assert(\n envelope.password_wrap.alg === SUPPORTED_WRAP_ALG,\n `Unsupported password_wrap.alg '${envelope.password_wrap.alg}', expected '${SUPPORTED_WRAP_ALG}'`,\n );\n assert(\n envelope.password_wrap.kdf === SUPPORTED_PASSWORD_WRAP_KDF,\n `Unsupported password_wrap.kdf '${envelope.password_wrap.kdf}', expected '${SUPPORTED_PASSWORD_WRAP_KDF}'`,\n );\n assert(\n typeof envelope.password_wrap.salt === \"string\" && envelope.password_wrap.salt.length > 0,\n \"password_wrap.salt is required\",\n );\n assert(\n typeof envelope.password_wrap.nonce === \"string\" && envelope.password_wrap.nonce.length > 0,\n \"password_wrap.nonce is required\",\n );\n assert(\n typeof envelope.password_wrap.ciphertext === \"string\" && envelope.password_wrap.ciphertext.length > 0,\n \"password_wrap.ciphertext is required\",\n );\n}\n\nexport async function createDualWrapEnvelope(\n params: CreateDualWrapEnvelopeParams,\n): Promise<WalletE2eeRecoveryEnvelope> {\n assert(params.chainId.length > 0, \"chainId is required\");\n assert(params.accountId.length > 0, \"accountId is required\");\n assert(params.backupPassword.length > 0, \"backupPassword is required\");\n assert(params.walletWrapKey.length >= KEY_BYTES, \"walletWrapKey must be at least 32 bytes\");\n\n const createdAtMs = params.createdAtMs ?? Date.now();\n const keyId = params.keyId ?? `k-${toBase64(randomBytes(8)).replace(/=+$/g, \"\")}`;\n const recoveryKey = params.recoveryKey ?? randomBytes(KEY_BYTES);\n assert(recoveryKey.length === KEY_BYTES, \"recoveryKey must be 32 bytes\");\n\n const aad = toUtf8(`briij-recovery-envelope-v1:${params.chainId}:${params.accountId}:${keyId}:${createdAtMs}`);\n const walletWrap = await encryptWrap(recoveryKey, {\n key: params.walletWrapKey,\n aad,\n kdf: \"sha256-context-v1\",\n });\n\n const passwordSalt = randomBytes(SALT_BYTES);\n const passwordWrapKey = await derivePasswordWrapKey(params.backupPassword, passwordSalt);\n const passwordWrap = await encryptWrap(recoveryKey, {\n key: passwordWrapKey,\n aad,\n kdf: \"pbkdf2-sha256-v1\",\n params: {\n iterations: PASSWORD_KDF_ITERATIONS,\n hash: \"SHA-256\",\n },\n });\n passwordWrap.salt = toBase64(passwordSalt);\n\n return {\n envelope_version: ENVELOPE_VERSION,\n chain_id: params.chainId,\n account_id: params.accountId,\n created_at_ms: createdAtMs,\n key_id: keyId,\n wallet_wrap: walletWrap,\n password_wrap: passwordWrap,\n };\n}\n\nexport async function unwrapWithWallet({ envelope, walletWrapKey }: UnwrapWithWalletParams): Promise<Uint8Array> {\n validateRecoveryEnvelopeShape(envelope);\n return await decryptWrap(envelope.wallet_wrap, walletWrapKey);\n}\n\nexport async function unwrapWithPassword({ envelope, backupPassword }: UnwrapWithPasswordParams): Promise<Uint8Array> {\n validateRecoveryEnvelopeShape(envelope);\n const passwordSalt = fromBase64(envelope.password_wrap.salt);\n const passwordWrapKey = await derivePasswordWrapKey(backupPassword, passwordSalt);\n return await decryptWrap(envelope.password_wrap, passwordWrapKey);\n}\n\nfunction canonicalizeHomeserver(homeserver: string): string {\n const trimmed = homeserver.trim().replace(/\\/+$/, \"\");\n try {\n const parsed = new URL(trimmed);\n parsed.hostname = parsed.hostname.toLowerCase();\n return parsed.toString().replace(/\\/+$/, \"\");\n } catch {\n return trimmed.toLowerCase();\n }\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,IAAMA,gBAAgB,GAAG,CAAC;AAC1B,IAAMC,SAAS,GAAG,EAAE;AACpB,IAAMC,WAAW,GAAG,EAAE;AACtB,IAAMC,UAAU,GAAG,EAAE;AACrB,IAAMC,uBAAuB,GAAG,MAAO;AACvC,IAAMC,kBAAkB,GAAG,aAAa;AACxC,IAAMC,yBAAyB,GAAG,mBAAmB;AACrD,IAAMC,2BAA2B,GAAG,kBAAkB;AAsBtD,SAASC,MAAMA,CAACC,SAAkB,EAAEC,OAAe,EAAqB;EACpE,IAAI,CAACD,SAAS,EAAE,MAAM,IAAIE,K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MAAM,GAAG,IAAIC,GAAG,CAACH,OAAO,CAAC;IAC/BE,MAAM,CAACE,QAAQ,GAAGF,MAAM,CAACE,QAAQ,CAACC,WAAW,CAAC,CAAC;IAC/C,OAAOH,MAAM,CAAC5H,QAAQ,CAAC,CAAC,CAAC4G,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;EAChD,CAAC,CAAC,OAAAoB,OAAA,EAAM;IACJ,OAAON,OAAO,CAACK,WAAW,CAAC,CAAC;EAChC;AACJ","ignoreList":[]}
@@ -24,5 +24,6 @@ export interface XrplIdentityMintResult extends XrplIdentityAccountData {
24
24
  }
25
25
  export declare function configureXrplIdentityMinting(config: Partial<XrplIdentityMintingConfig>): void;
26
26
  export declare function setXamanWalletForXrplIdentity(xamanWallet: XamanWalletAdapter): void;
27
- export declare function mintSoulboundIdentityNFT(matrixUserId: string): Promise<XrplIdentityMintResult | null>;
27
+ export declare function getConfiguredXrplIdentityMintingConfig(): Partial<XrplIdentityMintingConfig>;
28
+ export declare function mintSoulboundIdentityNFT(matrixUserId: string, config?: Partial<XrplIdentityMintingConfig>): Promise<XrplIdentityMintResult | null>;
28
29
  //# sourceMappingURL=identity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/xrpl/identity.ts"],"names":[],"mappings":"AA0BA,MAAM,WAAW,uBAAuB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IAC/B,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,aAAa,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzE;AAED,MAAM,WA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AAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,kBAAkB,CAAC;IAChC,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CAC5F;AAED,MAAM,WAAW,sBAAuB,SAAQ,uBAAuB;IACnE,MAAM,EAAE,OAAO,CAAC;CACnB;AAID,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAAG,IAAI,CAK7F;AAED,wBAAgB,6BAA6B,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI,CAKnF;AAED,wBAAgB,sCAAsC,IAAI,OAAO,CAAC,yBAAyB,CAAC,CAE3F;AAED,wBAAsB,wBAAwB,CAC1C,YAAY,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAC5C,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAiExC"}
@@ -34,16 +34,20 @@ export function setXamanWalletForXrplIdentity(xamanWallet) {
34
34
  xamanWallet
35
35
  });
36
36
  }
37
- export function mintSoulboundIdentityNFT(_x) {
37
+ export function getConfiguredXrplIdentityMintingConfig() {
38
+ return _objectSpread({}, mintingConfig);
39
+ }
40
+ export function mintSoulboundIdentityNFT(_x, _x2) {
38
41
  return _mintSoulboundIdentityNFT.apply(this, arguments);
39
42
  }
40
43
  function _mintSoulboundIdentityNFT() {
41
- _mintSoulboundIdentityNFT = _asyncToGenerator(function* (matrixUserId) {
44
+ _mintSoulboundIdentityNFT = _asyncToGenerator(function* (matrixUserId, config) {
45
+ var effectiveConfig = _objectSpread(_objectSpread({}, mintingConfig), config);
42
46
  var {
43
47
  homeserverBaseUrl,
44
48
  accessToken,
45
49
  xamanWallet
46
- } = mintingConfig;
50
+ } = effectiveConfig;
47
51
  if (!homeserverBaseUrl || !accessToken || !xamanWallet) {
48
52
  logger.warn("Skipping XRPL identity mint for %s: missing homeserver auth and/or Xaman wallet adapter", matrixUserId);
49
53
  return null;
@@ -55,12 +59,12 @@ function _mintSoulboundIdentityNFT() {
55
59
  });
56
60
  }
57
61
  var xrplAddress = yield xamanWallet.getAddress();
58
- var ipfsUri = yield buildIpfsUri(matrixUserId, xrplAddress);
62
+ var ipfsUri = yield buildIpfsUri(matrixUserId, xrplAddress, effectiveConfig);
59
63
  var encodedUri = toHex(ipfsUri);
60
- var xrplClient = new XrplClient(resolveXrplWebSocketUrl());
64
+ var xrplClient = new XrplClient(resolveXrplWebSocketUrl(effectiveConfig));
61
65
  yield xrplClient.connect();
62
66
  try {
63
- var _extractNftTokenId, _txResult$result;
67
+ var _extractTxScopedNftTo;
64
68
  var mintTransaction = {
65
69
  TransactionType: "NFTokenMint",
66
70
  Account: xrplAddress,
@@ -72,11 +76,8 @@ function _mintSoulboundIdentityNFT() {
72
76
  var {
73
77
  hash: txHash
74
78
  } = yield xamanWallet.signAndSubmit(autofilled);
75
- var txResult = yield xrplClient.request({
76
- command: "tx",
77
- transaction: txHash
78
- });
79
- var nftTokenId = (_extractNftTokenId = extractNftTokenId((_txResult$result = txResult.result) === null || _txResult$result === void 0 ? void 0 : _txResult$result.meta)) !== null && _extractNftTokenId !== void 0 ? _extractNftTokenId : yield findAccountNftByUri(xrplClient, xrplAddress, encodedUri);
79
+ var txResult = yield waitForValidation(xrplClient, txHash);
80
+ var nftTokenId = (_extractTxScopedNftTo = extractTxScopedNftTokenId(txResult.result)) !== null && _extractTxScopedNftTo !== void 0 ? _extractTxScopedNftTo : yield findAccountNftByUri(xrplClient, xrplAddress, encodedUri);
80
81
  if (!nftTokenId) {
81
82
  throw new Error("Unable to resolve NFTokenID for transaction ".concat(txHash));
82
83
  }
@@ -97,13 +98,13 @@ function _mintSoulboundIdentityNFT() {
97
98
  });
98
99
  return _mintSoulboundIdentityNFT.apply(this, arguments);
99
100
  }
100
- function buildIpfsUri(_x2, _x3) {
101
+ function buildIpfsUri(_x3, _x4, _x5) {
101
102
  return _buildIpfsUri.apply(this, arguments);
102
103
  }
103
104
  function _buildIpfsUri() {
104
- _buildIpfsUri = _asyncToGenerator(function* (matrixUserId, xrplAddress) {
105
- if (mintingConfig.ipfsUriFactory) {
106
- return yield mintingConfig.ipfsUriFactory(matrixUserId, xrplAddress);
105
+ _buildIpfsUri = _asyncToGenerator(function* (matrixUserId, xrplAddress, config) {
106
+ if (config.ipfsUriFactory) {
107
+ return yield config.ipfsUriFactory(matrixUserId, xrplAddress);
107
108
  }
108
109
  var payload = JSON.stringify({
109
110
  matrixUserId,
@@ -114,17 +115,37 @@ function _buildIpfsUri() {
114
115
  });
115
116
  return _buildIpfsUri.apply(this, arguments);
116
117
  }
117
- function resolveXrplWebSocketUrl() {
118
- var _mintingConfig$networ;
119
- if (mintingConfig.websocketUrl) return mintingConfig.websocketUrl;
120
- var network = (_mintingConfig$networ = mintingConfig.network) !== null && _mintingConfig$networ !== void 0 ? _mintingConfig$networ : DEFAULT_XRPL_NETWORK;
118
+ function resolveXrplWebSocketUrl(config) {
119
+ var _config$network;
120
+ if (config.websocketUrl) return config.websocketUrl;
121
+ var network = (_config$network = config.network) !== null && _config$network !== void 0 ? _config$network : DEFAULT_XRPL_NETWORK;
121
122
  return network === "mainnet" ? DEFAULT_XRPL_MAINNET_WS : DEFAULT_XRPL_TESTNET_WS;
122
123
  }
124
+ function waitForValidation(_x6, _x7) {
125
+ return _waitForValidation.apply(this, arguments);
126
+ }
127
+ function _waitForValidation() {
128
+ _waitForValidation = _asyncToGenerator(function* (xrplClient, txHash) {
129
+ for (var attempt = 0; attempt < 15; attempt += 1) {
130
+ var _response$result;
131
+ var response = yield xrplClient.request({
132
+ command: "tx",
133
+ transaction: txHash
134
+ });
135
+ if (((_response$result = response.result) === null || _response$result === void 0 ? void 0 : _response$result.validated) === true) {
136
+ return response;
137
+ }
138
+ yield sleep(1000);
139
+ }
140
+ throw new Error("Timed out waiting for XRPL tx validation: ".concat(txHash));
141
+ });
142
+ return _waitForValidation.apply(this, arguments);
143
+ }
123
144
  function accountDataUrl(baseUrl, matrixUserId) {
124
145
  var trimmedBaseUrl = baseUrl.replace(/\/+$/, "");
125
146
  return "".concat(trimmedBaseUrl, "/_matrix/client/v3/user/").concat(encodeURIComponent(matrixUserId), "/account_data/").concat(encodeURIComponent(XRPL_IDENTITY_ACCOUNT_DATA_TYPE));
126
147
  }
127
- function getIdentityAccountData(_x4, _x5, _x6) {
148
+ function getIdentityAccountData(_x8, _x9, _x0) {
128
149
  return _getIdentityAccountData.apply(this, arguments);
129
150
  }
130
151
  function _getIdentityAccountData() {
@@ -132,7 +153,7 @@ function _getIdentityAccountData() {
132
153
  var response = yield fetch(accountDataUrl(homeserverBaseUrl, matrixUserId), {
133
154
  method: "GET",
134
155
  headers: {
135
- Authorization: "Bearer ".concat(accessToken),
156
+ "Authorization": "Bearer ".concat(accessToken),
136
157
  "Content-Type": "application/json"
137
158
  }
138
159
  });
@@ -144,7 +165,7 @@ function _getIdentityAccountData() {
144
165
  });
145
166
  return _getIdentityAccountData.apply(this, arguments);
146
167
  }
147
- function setIdentityAccountData(_x7, _x8, _x9, _x0) {
168
+ function setIdentityAccountData(_x1, _x10, _x11, _x12) {
148
169
  return _setIdentityAccountData.apply(this, arguments);
149
170
  }
150
171
  function _setIdentityAccountData() {
@@ -152,7 +173,7 @@ function _setIdentityAccountData() {
152
173
  var response = yield fetch(accountDataUrl(homeserverBaseUrl, matrixUserId), {
153
174
  method: "PUT",
154
175
  headers: {
155
- Authorization: "Bearer ".concat(accessToken),
176
+ "Authorization": "Bearer ".concat(accessToken),
156
177
  "Content-Type": "application/json"
157
178
  },
158
179
  body: JSON.stringify(payload)
@@ -163,18 +184,18 @@ function _setIdentityAccountData() {
163
184
  });
164
185
  return _setIdentityAccountData.apply(this, arguments);
165
186
  }
166
- function findAccountNftByUri(_x1, _x10, _x11) {
187
+ function findAccountNftByUri(_x13, _x14, _x15) {
167
188
  return _findAccountNftByUri.apply(this, arguments);
168
189
  }
169
190
  function _findAccountNftByUri() {
170
191
  _findAccountNftByUri = _asyncToGenerator(function* (xrplClient, xrplAddress, encodedUri) {
171
- var _response$result, _nft$NFTokenID;
192
+ var _response$result2, _nft$NFTokenID;
172
193
  var response = yield xrplClient.request({
173
194
  command: "account_nfts",
174
195
  account: xrplAddress
175
196
  });
176
197
  var targetUri = encodedUri.toUpperCase();
177
- var nft = (_response$result = response.result) === null || _response$result === void 0 || (_response$result = _response$result.account_nfts) === null || _response$result === void 0 ? void 0 : _response$result.find(candidate => {
198
+ var nft = (_response$result2 = response.result) === null || _response$result2 === void 0 || (_response$result2 = _response$result2.account_nfts) === null || _response$result2 === void 0 ? void 0 : _response$result2.find(candidate => {
178
199
  var _candidate$URI;
179
200
  return ((_candidate$URI = candidate.URI) === null || _candidate$URI === void 0 ? void 0 : _candidate$URI.toUpperCase()) === targetUri;
180
201
  });
@@ -182,27 +203,18 @@ function _findAccountNftByUri() {
182
203
  });
183
204
  return _findAccountNftByUri.apply(this, arguments);
184
205
  }
185
- function extractNftTokenId(meta) {
186
- var _AffectedNodes;
187
- if (!meta || typeof meta !== "object") return null;
188
- var affectedNodes = (_AffectedNodes = meta.AffectedNodes) !== null && _AffectedNodes !== void 0 ? _AffectedNodes : [];
189
- for (var nodeWrapper of affectedNodes) {
190
- var _tokensContainer$NFTo;
191
- if (!nodeWrapper || typeof nodeWrapper !== "object") continue;
192
- var [nodeValue] = Object.values(nodeWrapper);
193
- if (!nodeValue || typeof nodeValue !== "object") continue;
194
- var newFields = nodeValue.NewFields;
195
- var finalFields = nodeValue.FinalFields;
196
- var tokensContainer = [newFields, finalFields].find(container => {
197
- if (!container || typeof container !== "object") return false;
198
- return Array.isArray(container.NFTokens);
199
- });
200
- var nftokens = (_tokensContainer$NFTo = tokensContainer === null || tokensContainer === void 0 ? void 0 : tokensContainer.NFTokens) !== null && _tokensContainer$NFTo !== void 0 ? _tokensContainer$NFTo : [];
201
- for (var tokenEntry of nftokens) {
202
- if (!tokenEntry || typeof tokenEntry !== "object") continue;
203
- var token = tokenEntry.NFToken;
204
- if (token !== null && token !== void 0 && token.NFTokenID) return token.NFTokenID;
205
- }
206
+ function extractTxScopedNftTokenId(result) {
207
+ if (!result || typeof result !== "object") {
208
+ return null;
209
+ }
210
+ var payload = result;
211
+ var directTokenId = payload["nftoken_id"];
212
+ if (typeof directTokenId === "string" && directTokenId.length > 0) {
213
+ return directTokenId;
214
+ }
215
+ var directAlternate = payload["NFTokenID"];
216
+ if (typeof directAlternate === "string" && directAlternate.length > 0) {
217
+ return directAlternate;
206
218
  }
207
219
  return null;
208
220
  }
@@ -210,4 +222,15 @@ function toHex(input) {
210
222
  var bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
211
223
  return Array.from(bytes).map(value => value.toString(16).padStart(2, "0")).join("").toUpperCase();
212
224
  }
225
+ function sleep(_x16) {
226
+ return _sleep.apply(this, arguments);
227
+ }
228
+ function _sleep() {
229
+ _sleep = _asyncToGenerator(function* (ms) {
230
+ yield new Promise(resolve => {
231
+ setTimeout(resolve, ms);
232
+ });
233
+ });
234
+ return _sleep.apply(this, arguments);
235
+ }
213
236
  //# sourceMappingURL=identity.js.map