@dimcool/sdk 0.1.12 → 0.1.14

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/index.cjs CHANGED
@@ -21751,6 +21751,29 @@ var VoteAccountLayout = BufferLayout.struct([
21751
21751
  BufferLayout.struct([BufferLayout.nu64("slot"), BufferLayout.nu64("timestamp")], "lastTimestamp")
21752
21752
  ]);
21753
21753
 
21754
+ // src/utils/base64.ts
21755
+ function base64ToBytes(base64) {
21756
+ if (typeof Buffer !== "undefined") {
21757
+ return Buffer.from(base64, "base64");
21758
+ }
21759
+ const binary = atob(base64);
21760
+ const bytes = new Uint8Array(binary.length);
21761
+ for (let i = 0; i < binary.length; i++) {
21762
+ bytes[i] = binary.charCodeAt(i);
21763
+ }
21764
+ return bytes;
21765
+ }
21766
+ function bytesToBase64(bytes) {
21767
+ if (typeof Buffer !== "undefined") {
21768
+ return Buffer.from(bytes).toString("base64");
21769
+ }
21770
+ let binary = "";
21771
+ for (let i = 0; i < bytes.length; i++) {
21772
+ binary += String.fromCharCode(bytes[i]);
21773
+ }
21774
+ return btoa(binary);
21775
+ }
21776
+
21754
21777
  // src/http-client.ts
21755
21778
  var HttpClient = class {
21756
21779
  constructor(baseUrl, storage, logger2, appId, autoPayConfig) {
@@ -22023,11 +22046,11 @@ var HttpClient = class {
22023
22046
  }
22024
22047
  }
22025
22048
  );
22026
- const unsignedTx = Transaction.from(
22027
- Buffer.from(prepare.transaction, "base64")
22028
- );
22049
+ const unsignedTx = Transaction.from(base64ToBytes(prepare.transaction));
22029
22050
  const signedTx = await this.signTransactionHandler(unsignedTx);
22030
- const signedTransaction = signedTx.serialize({ requireAllSignatures: false }).toString("base64");
22051
+ const signedTransaction = bytesToBase64(
22052
+ signedTx.serialize({ requireAllSignatures: false })
22053
+ );
22031
22054
  const submitted = await this.post(
22032
22055
  "/payments/submit",
22033
22056
  {
@@ -22043,19 +22066,6 @@ var HttpClient = class {
22043
22066
  };
22044
22067
 
22045
22068
  // src/auth.ts
22046
- function toBase64(bytes) {
22047
- if (typeof Buffer !== "undefined") {
22048
- return Buffer.from(bytes).toString("base64");
22049
- }
22050
- let binary = "";
22051
- for (let i = 0; i < bytes.length; i++) {
22052
- binary += String.fromCharCode(bytes[i]);
22053
- }
22054
- if (typeof btoa === "undefined") {
22055
- throw new Error("Base64 encoding is not available in this environment");
22056
- }
22057
- return btoa(binary);
22058
- }
22059
22069
  var Auth = class {
22060
22070
  constructor(http2, storage, wallet, logger2) {
22061
22071
  this.http = http2;
@@ -22120,7 +22130,7 @@ var Auth = class {
22120
22130
  }
22121
22131
  const { message } = await this.generateHandshake(address);
22122
22132
  const signatureResult = await this.wallet.signMessage(message);
22123
- const signedMessage = typeof signatureResult === "string" ? signatureResult : toBase64(signatureResult);
22133
+ const signedMessage = typeof signatureResult === "string" ? signatureResult : bytesToBase64(signatureResult);
22124
22134
  this.logger.debug("Auth.loginWithWallet called", {
22125
22135
  address,
22126
22136
  walletMeta: options?.walletMeta
@@ -22604,11 +22614,11 @@ var Games = class {
22604
22614
  );
22605
22615
  }
22606
22616
  const prepared = await this.prepareGameDonation(gameId, amountMinor);
22607
- const unsignedTx = Transaction.from(
22608
- Buffer.from(prepared.transaction, "base64")
22609
- );
22617
+ const unsignedTx = Transaction.from(base64ToBytes(prepared.transaction));
22610
22618
  const signedTx = await this.wallet.signTransaction(unsignedTx);
22611
- const signedTransaction = signedTx.serialize({ requireAllSignatures: false }).toString("base64");
22619
+ const signedTransaction = bytesToBase64(
22620
+ signedTx.serialize({ requireAllSignatures: false })
22621
+ );
22612
22622
  const result = await this.donateToGame(
22613
22623
  gameId,
22614
22624
  amountMinor,
@@ -22886,11 +22896,11 @@ var Tips = class {
22886
22896
  }
22887
22897
  const { publicKey: senderAddress } = await this.wallet.loadWallet();
22888
22898
  const prepared = await this.prepare({ recipientUsername, amount });
22889
- const unsignedTx = Transaction.from(
22890
- Buffer.from(prepared.transaction, "base64")
22891
- );
22899
+ const unsignedTx = Transaction.from(base64ToBytes(prepared.transaction));
22892
22900
  const signedTx = await this.wallet.signTransaction(unsignedTx);
22893
- const signedTxBase64 = signedTx.serialize({ requireAllSignatures: false }).toString("base64");
22901
+ const signedTxBase64 = bytesToBase64(
22902
+ signedTx.serialize({ requireAllSignatures: false })
22903
+ );
22894
22904
  const transfer = await this.wallet.submitTransfer(
22895
22905
  signedTxBase64,
22896
22906
  senderAddress,
@@ -23265,11 +23275,11 @@ var Wallet = class {
23265
23275
  amount,
23266
23276
  token
23267
23277
  );
23268
- const unsignedTx = Transaction.from(
23269
- Buffer.from(prepared.transaction, "base64")
23270
- );
23278
+ const unsignedTx = Transaction.from(base64ToBytes(prepared.transaction));
23271
23279
  const signedTx = await this.signTransaction(unsignedTx);
23272
- const signedTxBase64 = signedTx.serialize({ requireAllSignatures: false }).toString("base64");
23280
+ const signedTxBase64 = bytesToBase64(
23281
+ signedTx.serialize({ requireAllSignatures: false })
23282
+ );
23273
23283
  const submitted = await this.submitTransfer(
23274
23284
  signedTxBase64,
23275
23285
  senderAddress,
package/dist/index.js CHANGED
@@ -21710,6 +21710,29 @@ var VoteAccountLayout = BufferLayout.struct([
21710
21710
  BufferLayout.struct([BufferLayout.nu64("slot"), BufferLayout.nu64("timestamp")], "lastTimestamp")
21711
21711
  ]);
21712
21712
 
21713
+ // src/utils/base64.ts
21714
+ function base64ToBytes(base64) {
21715
+ if (typeof Buffer !== "undefined") {
21716
+ return Buffer.from(base64, "base64");
21717
+ }
21718
+ const binary = atob(base64);
21719
+ const bytes = new Uint8Array(binary.length);
21720
+ for (let i = 0; i < binary.length; i++) {
21721
+ bytes[i] = binary.charCodeAt(i);
21722
+ }
21723
+ return bytes;
21724
+ }
21725
+ function bytesToBase64(bytes) {
21726
+ if (typeof Buffer !== "undefined") {
21727
+ return Buffer.from(bytes).toString("base64");
21728
+ }
21729
+ let binary = "";
21730
+ for (let i = 0; i < bytes.length; i++) {
21731
+ binary += String.fromCharCode(bytes[i]);
21732
+ }
21733
+ return btoa(binary);
21734
+ }
21735
+
21713
21736
  // src/http-client.ts
21714
21737
  var HttpClient = class {
21715
21738
  constructor(baseUrl, storage, logger2, appId, autoPayConfig) {
@@ -21982,11 +22005,11 @@ var HttpClient = class {
21982
22005
  }
21983
22006
  }
21984
22007
  );
21985
- const unsignedTx = Transaction.from(
21986
- Buffer.from(prepare.transaction, "base64")
21987
- );
22008
+ const unsignedTx = Transaction.from(base64ToBytes(prepare.transaction));
21988
22009
  const signedTx = await this.signTransactionHandler(unsignedTx);
21989
- const signedTransaction = signedTx.serialize({ requireAllSignatures: false }).toString("base64");
22010
+ const signedTransaction = bytesToBase64(
22011
+ signedTx.serialize({ requireAllSignatures: false })
22012
+ );
21990
22013
  const submitted = await this.post(
21991
22014
  "/payments/submit",
21992
22015
  {
@@ -22002,19 +22025,6 @@ var HttpClient = class {
22002
22025
  };
22003
22026
 
22004
22027
  // src/auth.ts
22005
- function toBase64(bytes) {
22006
- if (typeof Buffer !== "undefined") {
22007
- return Buffer.from(bytes).toString("base64");
22008
- }
22009
- let binary = "";
22010
- for (let i = 0; i < bytes.length; i++) {
22011
- binary += String.fromCharCode(bytes[i]);
22012
- }
22013
- if (typeof btoa === "undefined") {
22014
- throw new Error("Base64 encoding is not available in this environment");
22015
- }
22016
- return btoa(binary);
22017
- }
22018
22028
  var Auth = class {
22019
22029
  constructor(http2, storage, wallet, logger2) {
22020
22030
  this.http = http2;
@@ -22079,7 +22089,7 @@ var Auth = class {
22079
22089
  }
22080
22090
  const { message } = await this.generateHandshake(address);
22081
22091
  const signatureResult = await this.wallet.signMessage(message);
22082
- const signedMessage = typeof signatureResult === "string" ? signatureResult : toBase64(signatureResult);
22092
+ const signedMessage = typeof signatureResult === "string" ? signatureResult : bytesToBase64(signatureResult);
22083
22093
  this.logger.debug("Auth.loginWithWallet called", {
22084
22094
  address,
22085
22095
  walletMeta: options?.walletMeta
@@ -22563,11 +22573,11 @@ var Games = class {
22563
22573
  );
22564
22574
  }
22565
22575
  const prepared = await this.prepareGameDonation(gameId, amountMinor);
22566
- const unsignedTx = Transaction.from(
22567
- Buffer.from(prepared.transaction, "base64")
22568
- );
22576
+ const unsignedTx = Transaction.from(base64ToBytes(prepared.transaction));
22569
22577
  const signedTx = await this.wallet.signTransaction(unsignedTx);
22570
- const signedTransaction = signedTx.serialize({ requireAllSignatures: false }).toString("base64");
22578
+ const signedTransaction = bytesToBase64(
22579
+ signedTx.serialize({ requireAllSignatures: false })
22580
+ );
22571
22581
  const result = await this.donateToGame(
22572
22582
  gameId,
22573
22583
  amountMinor,
@@ -22845,11 +22855,11 @@ var Tips = class {
22845
22855
  }
22846
22856
  const { publicKey: senderAddress } = await this.wallet.loadWallet();
22847
22857
  const prepared = await this.prepare({ recipientUsername, amount });
22848
- const unsignedTx = Transaction.from(
22849
- Buffer.from(prepared.transaction, "base64")
22850
- );
22858
+ const unsignedTx = Transaction.from(base64ToBytes(prepared.transaction));
22851
22859
  const signedTx = await this.wallet.signTransaction(unsignedTx);
22852
- const signedTxBase64 = signedTx.serialize({ requireAllSignatures: false }).toString("base64");
22860
+ const signedTxBase64 = bytesToBase64(
22861
+ signedTx.serialize({ requireAllSignatures: false })
22862
+ );
22853
22863
  const transfer = await this.wallet.submitTransfer(
22854
22864
  signedTxBase64,
22855
22865
  senderAddress,
@@ -23224,11 +23234,11 @@ var Wallet = class {
23224
23234
  amount,
23225
23235
  token
23226
23236
  );
23227
- const unsignedTx = Transaction.from(
23228
- Buffer.from(prepared.transaction, "base64")
23229
- );
23237
+ const unsignedTx = Transaction.from(base64ToBytes(prepared.transaction));
23230
23238
  const signedTx = await this.signTransaction(unsignedTx);
23231
- const signedTxBase64 = signedTx.serialize({ requireAllSignatures: false }).toString("base64");
23239
+ const signedTxBase64 = bytesToBase64(
23240
+ signedTx.serialize({ requireAllSignatures: false })
23241
+ );
23232
23242
  const submitted = await this.submitTransfer(
23233
23243
  signedTxBase64,
23234
23244
  senderAddress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimcool/sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",