@stellar/typescript-wallet-sdk 1.1.2 → 1.1.3

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.
@@ -54,3 +54,6 @@ export declare class WithdrawalTxNotPendingUserTransferStartError extends Error
54
54
  export declare class WithdrawalTxMissingMemoError extends Error {
55
55
  constructor();
56
56
  }
57
+ export declare class WithdrawalTxMemoError extends Error {
58
+ constructor();
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar/typescript-wallet-sdk",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },
@@ -40,7 +40,7 @@
40
40
  "jws": "^4.0.0",
41
41
  "lodash": "^4.17.21",
42
42
  "query-string": "^7.1.3",
43
- "stellar-sdk": "^10.4.1",
43
+ "stellar-sdk": "^11.0.0-beta.3",
44
44
  "stream-http": "^3.2.0",
45
45
  "url": "^0.11.0",
46
46
  "util": "^0.12.5",
@@ -146,3 +146,10 @@ export class WithdrawalTxMissingMemoError extends Error {
146
146
  Object.setPrototypeOf(this, WithdrawalTxMissingMemoError.prototype);
147
147
  }
148
148
  }
149
+
150
+ export class WithdrawalTxMemoError extends Error {
151
+ constructor() {
152
+ super(`Error parsing withdrawal transaction memo`);
153
+ Object.setPrototypeOf(this, WithdrawalTxMemoError.prototype);
154
+ }
155
+ }
@@ -14,6 +14,7 @@ import {
14
14
  InsufficientStartingBalanceError,
15
15
  WithdrawalTxMissingMemoError,
16
16
  WithdrawalTxNotPendingUserTransferStartError,
17
+ WithdrawalTxMemoError,
17
18
  } from "../../Exceptions";
18
19
  import { IssuedAssetId, StellarAssetId } from "../../Asset";
19
20
  import { WithdrawTransaction, TransactionStatus } from "../../Types";
@@ -129,9 +130,21 @@ export class TransactionBuilder {
129
130
  throw new WithdrawalTxMissingMemoError();
130
131
  }
131
132
 
132
- return this.setMemo(
133
- new Memo(transaction.withdraw_memo_type, transaction.withdraw_memo),
134
- ).transfer(
133
+ if (transaction.withdraw_memo_type === "hash") {
134
+ try {
135
+ const buffer = Buffer.from(transaction.withdraw_memo, "base64");
136
+ const memo = Memo.hash(buffer.toString("hex"));
137
+ this.setMemo(memo);
138
+ } catch {
139
+ throw new WithdrawalTxMemoError();
140
+ }
141
+ } else {
142
+ this.setMemo(
143
+ new Memo(transaction.withdraw_memo_type, transaction.withdraw_memo),
144
+ );
145
+ }
146
+
147
+ return this.transfer(
135
148
  transaction.withdraw_anchor_account,
136
149
  assetId,
137
150
  transaction.amount_in,
@@ -36,7 +36,7 @@ describe("Stellar", () => {
36
36
  } catch (e) {
37
37
  await axios.get("https://friendbot.stellar.org/?addr=" + kp.publicKey);
38
38
  }
39
- });
39
+ }, 10000);
40
40
  it("should create and submit a transaction", async () => {
41
41
  const now = Math.floor(Date.now() / 1000) - 5;
42
42
 
@@ -198,32 +198,53 @@ describe("Stellar", () => {
198
198
  kp.sign(tx);
199
199
  });
200
200
  it("should transfer withdrawal transaction", async () => {
201
- const walletTransaction = {
202
- id: "db15d166-5a5e-4d5c-ba5d-271c32cd8cf0",
203
- kind: "withdrawal",
204
- status: TransactionStatus.pending_user_transfer_start,
205
- amount_in: "50.55",
206
- withdraw_memo_type: "text",
207
- withdraw_memo: "the withdraw memo",
208
- withdraw_anchor_account:
209
- "GCSGSR6KQQ5BP2FXVPWRL6SWPUSFWLVONLIBJZUKTVQB5FYJFVL6XOXE",
210
- } as WithdrawTransaction;
201
+ const memoExamples = [
202
+ {
203
+ type: "text",
204
+ value: "example text",
205
+ },
206
+ {
207
+ type: "id",
208
+ value: "12345",
209
+ },
210
+ {
211
+ type: "hash",
212
+ value: "AAAAAAAAAAAAAAAAAAAAAMAP+8deo0TViBD09TfOBY0=",
213
+ },
214
+ {
215
+ type: "hash",
216
+ value: "MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=",
217
+ },
218
+ ];
211
219
 
212
- const asset = new IssuedAssetId(
213
- "USDC",
214
- "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
215
- );
220
+ for (const memoExample of memoExamples) {
221
+ const walletTransaction = {
222
+ id: "db15d166-5a5e-4d5c-ba5d-271c32cd8cf0",
223
+ kind: "withdrawal",
224
+ status: TransactionStatus.pending_user_transfer_start,
225
+ amount_in: "50.55",
226
+ withdraw_memo_type: memoExample.type,
227
+ withdraw_memo: memoExample.value,
228
+ withdraw_anchor_account:
229
+ "GCSGSR6KQQ5BP2FXVPWRL6SWPUSFWLVONLIBJZUKTVQB5FYJFVL6XOXE",
230
+ } as WithdrawTransaction;
216
231
 
217
- const txBuilder = await stellar.transaction({
218
- sourceAddress: kp,
219
- baseFee: 100,
220
- });
232
+ const asset = new IssuedAssetId(
233
+ "USDC",
234
+ "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
235
+ );
221
236
 
222
- const txn = txBuilder
223
- .transferWithdrawalTransaction(walletTransaction, asset)
224
- .build();
225
- expect(txn).toBeTruthy();
226
- });
237
+ const txBuilder = await stellar.transaction({
238
+ sourceAddress: kp,
239
+ baseFee: 100,
240
+ });
241
+
242
+ const txn = txBuilder
243
+ .transferWithdrawalTransaction(walletTransaction, asset)
244
+ .build();
245
+ expect(txn).toBeTruthy();
246
+ }
247
+ }, 20000);
227
248
  });
228
249
 
229
250
  describe("Asset", () => {