@usebutr/core 0.5.0 → 1.0.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.
- package/dist/index.d.ts +367 -352
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types/chain.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types/chain.ts","../src/types/account.ts","../src/types/capabilities.ts","../src/types/platform.ts","../src/types/chains-by-platform.ts","../src/types/connector.ts","../src/types/wallet.ts","../src/types/discoverer.ts","../src/types/errors.ts","../src/storage/persistence.ts","../src/storage/snapshot.ts","../src/types/manager.ts","../src/types/signer.ts","../src/wallet-source.ts","../src/store/reducer.ts","../src/store/shadow-adapter.ts","../src/storage/browser-storage-driver.ts","../src/storage/cookie-storage-driver.ts","../src/storage/wallet-storage.ts","../src/store/wallet-store.ts","../src/wallet-equal.ts","../src/logger.ts","../src/sanitize-icon.ts","../src/encoding/bytes.ts"],"mappings":";;;;;;;;KAOK;;EAEH;;EAEA;;EAEA;;EAEA;;;;KCbG;EACH,OAAO;EACP;EACA;;;;;;;;;cAUI,eAAgB,iBAAiB,OAAO,cAAY;KAMrD;;EAEH;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;;;;;;;;;;;;KCTG;;EAEH;;EAEA;;;EAGA;;;EAGA;;;EAGA;;;EAGA;;;;;;EAMA;;EAEA;;;;EAIA;;;;EAIA;;;;;;;;;;;cC7CI;KAED,wBAAwB;;;;;;;;;;;;;KCIxB,mBAAmB,SAAS,OAAO,eAAe,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4B/D,wBAAyB,SAAS,QAAQ,sBAAoB;;;;;;;;;;;;KC5B/D;;;;;;;;;;;;;;;;;;;;KAqBA;EACC,SAA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CpLzC,aAAa,KAAK;EAAY,sBAAsB;IAAM;KAE1D;EACH,SAAS;EACT,UAAU;EACV,gBACE,qBACA,aAAa,QAAQ,0BACrB,WAAW,OAAO,mBACf;EACL,mBAAmB;EACnB,uBAAuB,eAAe,WAAW;EACjD,sBAAsB;EACtB,gBAAgB;EAChB,kBAAkB,wBAAwB;EAC1C;EACA;EACA,qBAAqB;EACrB,qBAAqB,OAAO;EAC5B,eAAe,eAAe,eAAe;EAC7C,sBAAsB;EACtB,wBAAwB,wBAAwB;EAChD,sBAAsB,qBAAqB,SAAS;;KAGjD,cAAc,kBAAkB;KAChC,mBAAmB,aAAa;cAE/B,oBAAqB,QAAQ,kDAAmB,SAAA,QAAA;;;;;;;;;;;;;;;;;;;;cCpFhD,cAAe,GAAG,6BAA6B,GAAG;;;cClBlD,aAAc,MAAM;cAIpB,cAAe,MAAM;;;;;;;;;;;;;;;;;;cCUrB,eAAgB;;;;;;;;;;;;;;;;;;;;cCWhB,aAAc,OAAO;;cASrB,qBAAsB,OAAO;;;;;;cAO7B,aAAc,gBAAc;;;;;cAoB5B,gBAAiB,gBAAc;;cAU/B,gBAAiB,OAAO;;;;;;cAaxB,gBAAiB,OAAO;;;cAsBxB,gBAAiB,kBAAgB"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { createStore } from "zustand/vanilla";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
|
+
//#region src/types/account.ts
|
|
5
|
+
/**
|
|
6
|
+
* Build butr's `Account` shape from a wallet address and a resolved
|
|
7
|
+
* `ChainBase`. The composite id (`<chain>:<address>`) is what the
|
|
8
|
+
* reducer uses to compare accounts across refreshes, so every adapter
|
|
9
|
+
* must build accounts through this helper (or keep the format
|
|
10
|
+
* byte-identical).
|
|
11
|
+
*/
|
|
12
|
+
const buildAccount = (address, chain) => ({
|
|
13
|
+
chain,
|
|
14
|
+
id: `${chain.id}:${address}`,
|
|
15
|
+
walletAddress: address
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
4
19
|
//#region src/types/chains-by-platform.ts
|
|
5
20
|
/**
|
|
6
21
|
* Build a fully-populated `ChainsByPlatform` from a partial. Platforms
|
|
@@ -106,7 +121,7 @@ const mapConnectionError = (raw) => {
|
|
|
106
121
|
};
|
|
107
122
|
|
|
108
123
|
//#endregion
|
|
109
|
-
//#region src/types/
|
|
124
|
+
//#region src/types/platform.ts
|
|
110
125
|
/**
|
|
111
126
|
* Canonical list of supported chain platforms. The single runtime source
|
|
112
127
|
* of truth: `ChainPlatform` is derived from it, and storage validators
|
|
@@ -121,18 +136,6 @@ const CHAIN_PLATFORMS = [
|
|
|
121
136
|
"bitcoin",
|
|
122
137
|
"polkadot"
|
|
123
138
|
];
|
|
124
|
-
/**
|
|
125
|
-
* Build butr's `Account` shape from a wallet address and a resolved
|
|
126
|
-
* `ChainBase`. The composite id (`<chain>:<address>`) is what the
|
|
127
|
-
* reducer uses to compare accounts across refreshes, so every adapter
|
|
128
|
-
* must build accounts through this helper (or keep the format
|
|
129
|
-
* byte-identical).
|
|
130
|
-
*/
|
|
131
|
-
const buildAccount = (address, chain) => ({
|
|
132
|
-
chain,
|
|
133
|
-
id: `${chain.id}:${address}`,
|
|
134
|
-
walletAddress: address
|
|
135
|
-
});
|
|
136
139
|
|
|
137
140
|
//#endregion
|
|
138
141
|
//#region src/wallet-source.ts
|
|
@@ -1448,6 +1451,10 @@ const sanitizeIcon = (icon) => {
|
|
|
1448
1451
|
* - {@link bytesToHexPrefixed} returns `0x`-prefixed hex (EVM, Polkadot).
|
|
1449
1452
|
* - {@link hexToBytes} tolerantly strips an optional `0x` (all callers).
|
|
1450
1453
|
*/
|
|
1454
|
+
/** Bitcoin/Solana alphabet; omits the visually ambiguous `0`, `O`, `I`, `l`. */
|
|
1455
|
+
const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1456
|
+
const BASE58_INDEX = /* @__PURE__ */ new Map();
|
|
1457
|
+
for (let i = 0; i < 58; i += 1) BASE58_INDEX.set(BASE58_ALPHABET[i] ?? "", i);
|
|
1451
1458
|
/** Bare lowercase hex, no `0x` prefix (Bitcoin, Ledger). */
|
|
1452
1459
|
const bytesToHex = (bytes) => {
|
|
1453
1460
|
let hex = "";
|
|
@@ -1488,7 +1495,49 @@ const bytesToBase64 = (bytes) => {
|
|
|
1488
1495
|
for (const byte of bytes) binary += String.fromCodePoint(byte);
|
|
1489
1496
|
return btoa(binary);
|
|
1490
1497
|
};
|
|
1498
|
+
/**
|
|
1499
|
+
* `Uint8Array` → base58 (Solana addresses and signatures). Leading zero
|
|
1500
|
+
* bytes are significant in base58 and survive the BigInt round-trip only
|
|
1501
|
+
* because they're re-prefixed as `1`s afterwards.
|
|
1502
|
+
*/
|
|
1503
|
+
const bytesToBase58 = (bytes) => {
|
|
1504
|
+
let intVal = 0n;
|
|
1505
|
+
for (const byte of bytes) intVal = intVal << 8n | BigInt(byte);
|
|
1506
|
+
let out = "";
|
|
1507
|
+
while (intVal > 0n) {
|
|
1508
|
+
const remainder = intVal % 58n;
|
|
1509
|
+
intVal /= 58n;
|
|
1510
|
+
out = BASE58_ALPHABET[Number(remainder)] + out;
|
|
1511
|
+
}
|
|
1512
|
+
for (const byte of bytes) {
|
|
1513
|
+
if (byte !== 0) break;
|
|
1514
|
+
out = `1${out}`;
|
|
1515
|
+
}
|
|
1516
|
+
return out;
|
|
1517
|
+
};
|
|
1518
|
+
/** Decode base58 into raw bytes. Throws on characters outside the alphabet
|
|
1519
|
+
* rather than silently dropping them. */
|
|
1520
|
+
const base58ToBytes = (input) => {
|
|
1521
|
+
let intVal = 0n;
|
|
1522
|
+
let leadingZeros = 0;
|
|
1523
|
+
let stillLeading = true;
|
|
1524
|
+
for (const char of input) {
|
|
1525
|
+
if (stillLeading && char === "1") leadingZeros += 1;
|
|
1526
|
+
else stillLeading = false;
|
|
1527
|
+
const digit = BASE58_INDEX.get(char);
|
|
1528
|
+
if (digit === void 0) throw new Error(`Invalid base58 character "${char}"`);
|
|
1529
|
+
intVal = intVal * 58n + BigInt(digit);
|
|
1530
|
+
}
|
|
1531
|
+
const bytes = [];
|
|
1532
|
+
const byteMask = 255n;
|
|
1533
|
+
while (intVal > 0n) {
|
|
1534
|
+
bytes.unshift(Number(intVal & byteMask));
|
|
1535
|
+
intVal >>= 8n;
|
|
1536
|
+
}
|
|
1537
|
+
for (let i = 0; i < leadingZeros; i += 1) bytes.unshift(0);
|
|
1538
|
+
return Uint8Array.from(bytes);
|
|
1539
|
+
};
|
|
1491
1540
|
|
|
1492
1541
|
//#endregion
|
|
1493
|
-
export { CHAIN_PLATFORMS, EMPTY_SNAPSHOT, ShadowConnectorError, WalletStorage, base64ToBytes, buildAccount, buildChainsByPlatform, bytesToBase64, bytesToHex, bytesToHexPrefixed, createBrowserStorageDriver, createCookieStorageDriver, createMemoryStorageDriver, createWalletSource, createWalletStore, hexToBytes, isShadowAdapter, logError, logWarn, mapConnectionError, readWalletSnapshot, sanitizeIcon, walletEqual };
|
|
1542
|
+
export { CHAIN_PLATFORMS, EMPTY_SNAPSHOT, ShadowConnectorError, WalletStorage, base58ToBytes, base64ToBytes, buildAccount, buildChainsByPlatform, bytesToBase58, bytesToBase64, bytesToHex, bytesToHexPrefixed, createBrowserStorageDriver, createCookieStorageDriver, createMemoryStorageDriver, createWalletSource, createWalletStore, hexToBytes, isShadowAdapter, logError, logWarn, mapConnectionError, readWalletSnapshot, sanitizeIcon, walletEqual };
|
|
1494
1543
|
//# sourceMappingURL=index.js.map
|