@armory-sh/client-ethers 0.2.24 → 0.2.25-alpha.21.67

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 (2) hide show
  1. package/dist/index.js +53 -3
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -116,6 +116,56 @@ async function recoverEIP3009Signer(params, signature, domain) {
116
116
  return address;
117
117
  }
118
118
 
119
+ // src/bytes.ts
120
+ var textEncoder = new TextEncoder();
121
+ var textDecoder = new TextDecoder();
122
+ function getNodeBuffer() {
123
+ if ("Buffer" in globalThis) {
124
+ return globalThis.Buffer;
125
+ }
126
+ return void 0;
127
+ }
128
+ function toBase64(bytes) {
129
+ if (typeof btoa === "function") {
130
+ let binary = "";
131
+ for (let index = 0; index < bytes.length; index += 1) {
132
+ binary += String.fromCharCode(bytes[index]);
133
+ }
134
+ return btoa(binary);
135
+ }
136
+ const nodeBuffer = getNodeBuffer();
137
+ if (nodeBuffer) {
138
+ return nodeBuffer.from(bytes).toString("base64");
139
+ }
140
+ throw new Error("No base64 encoder available in this runtime");
141
+ }
142
+ function fromBase64(base64) {
143
+ if (typeof atob === "function") {
144
+ const binary = atob(base64);
145
+ const bytes = new Uint8Array(binary.length);
146
+ for (let index = 0; index < binary.length; index += 1) {
147
+ bytes[index] = binary.charCodeAt(index);
148
+ }
149
+ return bytes;
150
+ }
151
+ const nodeBuffer = getNodeBuffer();
152
+ if (nodeBuffer) {
153
+ return Uint8Array.from(nodeBuffer.from(base64, "base64"));
154
+ }
155
+ throw new Error("No base64 decoder available in this runtime");
156
+ }
157
+ function encodeUtf8ToBase64(value) {
158
+ const bytes = textEncoder.encode(value);
159
+ return toBase64(bytes);
160
+ }
161
+ function decodeBase64ToUtf8(value) {
162
+ const bytes = fromBase64(value);
163
+ return textDecoder.decode(bytes);
164
+ }
165
+ function normalizeBase64Url(value) {
166
+ return value.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(value.length / 4) * 4, "=");
167
+ }
168
+
119
169
  // src/protocol.ts
120
170
  function detectX402Version(_response) {
121
171
  return 2;
@@ -128,8 +178,8 @@ function parseJsonOrBase64(value) {
128
178
  return JSON.parse(value);
129
179
  } catch {
130
180
  }
131
- const normalized = value.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(value.length / 4) * 4, "=");
132
- return JSON.parse(Buffer.from(normalized, "base64").toString("utf-8"));
181
+ const normalized = normalizeBase64Url(value);
182
+ return JSON.parse(decodeBase64ToUtf8(normalized));
133
183
  }
134
184
  function parsePaymentRequired(response) {
135
185
  const v2Header = response.headers.get(V2_HEADERS.PAYMENT_REQUIRED);
@@ -217,7 +267,7 @@ async function createX402Payment(signer, parsed, fromAddress, nonce, validBefore
217
267
  );
218
268
  }
219
269
  function encodeX402Payment(payload) {
220
- return Buffer.from(JSON.stringify(payload)).toString("base64");
270
+ return encodeUtf8ToBase64(JSON.stringify(payload));
221
271
  }
222
272
  var defaultConfig = {
223
273
  baseURL: "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armory-sh/client-ethers",
3
- "version": "0.2.24",
3
+ "version": "0.2.25-alpha.21.67",
4
4
  "license": "MIT",
5
5
  "author": "Sawyer Cutler <sawyer@dirtroad.dev>",
6
6
  "keywords": [
@@ -29,7 +29,7 @@
29
29
  "exports": {
30
30
  ".": {
31
31
  "types": "./dist/index.d.ts",
32
- "bun": "./src/index.ts",
32
+ "bun": "./dist/index.js",
33
33
  "default": "./dist/index.js"
34
34
  },
35
35
  "./dist/*": "./dist/*.js"
@@ -47,7 +47,7 @@
47
47
  "directory": "packages/client-ethers"
48
48
  },
49
49
  "dependencies": {
50
- "@armory-sh/base": "0.2.25",
50
+ "@armory-sh/base": "0.2.26-alpha.21.67",
51
51
  "ethers": "6.16.0"
52
52
  },
53
53
  "devDependencies": {