@d9-network/spec 1.0.2 → 1.2.2

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.cts CHANGED
@@ -8716,5 +8716,82 @@ interface FormatDurationOptions {
8716
8716
  */
8717
8717
  declare function formatBlockDuration(blocks: number, options?: FormatDurationOptions): string;
8718
8718
  //#endregion
8719
- export { AbortedError, ArithmeticError, BLOCKS_PER_DAY, BLOCKS_PER_HOUR, BLOCKS_PER_MINUTE, BLOCKS_PER_WEEK, BalanceStatus, BalancesTypesReasons, ContractError, type ContractErrorType, ContractExecutionError, D9, D9Apis, D9CallData, D9Calls, D9Constants, D9DispatchError, D9Errors, D9Events, D9Extensions, D9Queries, D9ViewFns, D9WhitelistEntry, D9_BLOCK_TIME_MS, D9_DECIMALS, D9_SS58_PREFIX, D9_SYMBOL, D9_TOKEN, DecodeError, DigestItem, DispatchClass, EncodeError, FormatBalanceOptions, FormatDurationOptions, GrandpaEquivocation, GrandpaEvent, GrandpaStoredState, type HexString, LangError, MetadataError, MultiAddress, NetworkError, Phase, type PolkadotSigner, type SS58String, SessionEvent, SignerError, Sr25519Keypair, TimeoutError, TokenConfig, TransactionError, TransactionPaymentEvent, TransactionPaymentReleases, TransactionalError, USDT_DECIMALS, USDT_SYMBOL, USDT_TOKEN, WalletAccount, WhitelistEntriesByChain, WhitelistEntry, addressesEqual, blocksToMs, blocksUntil, bytesToHex, index_d_exports as contracts, createAccountFromMnemonic, createAccountFromPrivateKey, createSr25519SignerFromKeypair, _allDescriptors as d9, estimateBlockAtTime, estimateTimeAtBlock, formatBalance, formatBlockDuration, formatTokenAmount, generateMnemonic, getAddressPrefix, getMetadata, hexToBytes, isContractError, isErrorType, isHexString, isValidAddress, isValidAddressForNetwork, isValidD9Address, mnemonicToMiniSecret, msToBlocks, parseAmount, sr25519AddressFromKeypair, sr25519AddressFromSecretKeyHex, sr25519DeriveFromMiniSecret, sr25519KeypairFromMiniSecret, ss58DecodePublicKey, ss58Reencode, toD9Address, toNetworkAddress, validateMnemonic };
8719
+ //#region src/utils/bytes.d.ts
8720
+ /**
8721
+ * Concatenate multiple Uint8Arrays into one
8722
+ *
8723
+ * @param arrays - Arrays to concatenate
8724
+ * @returns Combined Uint8Array
8725
+ *
8726
+ * @example
8727
+ * ```ts
8728
+ * const selector = hexToBytes("0xdb20f9f5");
8729
+ * const args = encodeArgs(...);
8730
+ * const callData = concatBytes(selector, args);
8731
+ * ```
8732
+ */
8733
+ declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
8734
+ /**
8735
+ * Compare two Uint8Arrays for equality
8736
+ *
8737
+ * @param a - First array
8738
+ * @param b - Second array
8739
+ * @returns True if arrays are equal
8740
+ */
8741
+ declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
8742
+ /**
8743
+ * Extract a slice from a Uint8Array with bounds checking
8744
+ *
8745
+ * @param data - Source array
8746
+ * @param start - Start index
8747
+ * @param length - Optional length (defaults to rest of array)
8748
+ * @returns Sliced array
8749
+ * @throws If indices are out of bounds
8750
+ */
8751
+ declare function safeSlice(data: Uint8Array, start: number, length?: number): Uint8Array;
8752
+ /**
8753
+ * Extract selector (first 4 bytes) from call data
8754
+ *
8755
+ * @param callData - The call data (Uint8Array or hex string)
8756
+ * @returns 4-byte selector
8757
+ * @throws If data is less than 4 bytes
8758
+ *
8759
+ * @example
8760
+ * ```ts
8761
+ * const selector = extractSelector(callData);
8762
+ * const selectorHex = bytesToHex(selector); // "0xdb20f9f5"
8763
+ * ```
8764
+ */
8765
+ declare function extractSelector(callData: Uint8Array | HexString$1): Uint8Array;
8766
+ /**
8767
+ * Extract selector as hex string from call data
8768
+ *
8769
+ * @param callData - The call data (Uint8Array or hex string)
8770
+ * @returns Hex string without 0x prefix (e.g., "db20f9f5")
8771
+ *
8772
+ * @example
8773
+ * ```ts
8774
+ * const selectorHex = extractSelectorHex(callData);
8775
+ * if (selectorHex === "db20f9f5") {
8776
+ * // PSP22::transfer
8777
+ * }
8778
+ * ```
8779
+ */
8780
+ declare function extractSelectorHex(callData: Uint8Array | HexString$1): string;
8781
+ /**
8782
+ * Normalize a hex string (ensure 0x prefix, lowercase)
8783
+ *
8784
+ * @param hex - Hex string with or without 0x prefix
8785
+ * @returns Normalized hex string with 0x prefix
8786
+ */
8787
+ declare function normalizeHex(hex: string): HexString$1;
8788
+ /**
8789
+ * Convert a selector string (with or without 0x) to Uint8Array
8790
+ *
8791
+ * @param selector - Selector as hex string
8792
+ * @returns 4-byte Uint8Array
8793
+ */
8794
+ declare function selectorToBytes(selector: string): Uint8Array;
8795
+ //#endregion
8796
+ export { AbortedError, ArithmeticError, BLOCKS_PER_DAY, BLOCKS_PER_HOUR, BLOCKS_PER_MINUTE, BLOCKS_PER_WEEK, BalanceStatus, BalancesTypesReasons, ContractError, type ContractErrorType, ContractExecutionError, D9, D9Apis, D9CallData, D9Calls, D9Constants, D9DispatchError, D9Errors, D9Events, D9Extensions, D9Queries, D9ViewFns, D9WhitelistEntry, D9_BLOCK_TIME_MS, D9_DECIMALS, D9_SS58_PREFIX, D9_SYMBOL, D9_TOKEN, DecodeError, DigestItem, DispatchClass, EncodeError, FormatBalanceOptions, FormatDurationOptions, GrandpaEquivocation, GrandpaEvent, GrandpaStoredState, type HexString, LangError, MetadataError, MultiAddress, NetworkError, Phase, type PolkadotSigner, type SS58String, SessionEvent, SignerError, Sr25519Keypair, TimeoutError, TokenConfig, TransactionError, TransactionPaymentEvent, TransactionPaymentReleases, TransactionalError, USDT_DECIMALS, USDT_SYMBOL, USDT_TOKEN, WalletAccount, WhitelistEntriesByChain, WhitelistEntry, addressesEqual, blocksToMs, blocksUntil, bytesEqual, bytesToHex, concatBytes, index_d_exports as contracts, createAccountFromMnemonic, createAccountFromPrivateKey, createSr25519SignerFromKeypair, _allDescriptors as d9, estimateBlockAtTime, estimateTimeAtBlock, extractSelector, extractSelectorHex, formatBalance, formatBlockDuration, formatTokenAmount, generateMnemonic, getAddressPrefix, getMetadata, hexToBytes, isContractError, isErrorType, isHexString, isValidAddress, isValidAddressForNetwork, isValidD9Address, mnemonicToMiniSecret, msToBlocks, normalizeHex, parseAmount, safeSlice, selectorToBytes, sr25519AddressFromKeypair, sr25519AddressFromSecretKeyHex, sr25519DeriveFromMiniSecret, sr25519KeypairFromMiniSecret, ss58DecodePublicKey, ss58Reencode, toD9Address, toNetworkAddress, validateMnemonic };
8720
8797
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -8716,5 +8716,82 @@ interface FormatDurationOptions {
8716
8716
  */
8717
8717
  declare function formatBlockDuration(blocks: number, options?: FormatDurationOptions): string;
8718
8718
  //#endregion
8719
- export { AbortedError, ArithmeticError, BLOCKS_PER_DAY, BLOCKS_PER_HOUR, BLOCKS_PER_MINUTE, BLOCKS_PER_WEEK, BalanceStatus, BalancesTypesReasons, ContractError, type ContractErrorType, ContractExecutionError, D9, D9Apis, D9CallData, D9Calls, D9Constants, D9DispatchError, D9Errors, D9Events, D9Extensions, D9Queries, D9ViewFns, D9WhitelistEntry, D9_BLOCK_TIME_MS, D9_DECIMALS, D9_SS58_PREFIX, D9_SYMBOL, D9_TOKEN, DecodeError, DigestItem, DispatchClass, EncodeError, FormatBalanceOptions, FormatDurationOptions, GrandpaEquivocation, GrandpaEvent, GrandpaStoredState, type HexString, LangError, MetadataError, MultiAddress, NetworkError, Phase, type PolkadotSigner, type SS58String, SessionEvent, SignerError, Sr25519Keypair, TimeoutError, TokenConfig, TransactionError, TransactionPaymentEvent, TransactionPaymentReleases, TransactionalError, USDT_DECIMALS, USDT_SYMBOL, USDT_TOKEN, WalletAccount, WhitelistEntriesByChain, WhitelistEntry, addressesEqual, blocksToMs, blocksUntil, bytesToHex, index_d_exports as contracts, createAccountFromMnemonic, createAccountFromPrivateKey, createSr25519SignerFromKeypair, _allDescriptors as d9, estimateBlockAtTime, estimateTimeAtBlock, formatBalance, formatBlockDuration, formatTokenAmount, generateMnemonic, getAddressPrefix, getMetadata, hexToBytes, isContractError, isErrorType, isHexString, isValidAddress, isValidAddressForNetwork, isValidD9Address, mnemonicToMiniSecret, msToBlocks, parseAmount, sr25519AddressFromKeypair, sr25519AddressFromSecretKeyHex, sr25519DeriveFromMiniSecret, sr25519KeypairFromMiniSecret, ss58DecodePublicKey, ss58Reencode, toD9Address, toNetworkAddress, validateMnemonic };
8719
+ //#region src/utils/bytes.d.ts
8720
+ /**
8721
+ * Concatenate multiple Uint8Arrays into one
8722
+ *
8723
+ * @param arrays - Arrays to concatenate
8724
+ * @returns Combined Uint8Array
8725
+ *
8726
+ * @example
8727
+ * ```ts
8728
+ * const selector = hexToBytes("0xdb20f9f5");
8729
+ * const args = encodeArgs(...);
8730
+ * const callData = concatBytes(selector, args);
8731
+ * ```
8732
+ */
8733
+ declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
8734
+ /**
8735
+ * Compare two Uint8Arrays for equality
8736
+ *
8737
+ * @param a - First array
8738
+ * @param b - Second array
8739
+ * @returns True if arrays are equal
8740
+ */
8741
+ declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
8742
+ /**
8743
+ * Extract a slice from a Uint8Array with bounds checking
8744
+ *
8745
+ * @param data - Source array
8746
+ * @param start - Start index
8747
+ * @param length - Optional length (defaults to rest of array)
8748
+ * @returns Sliced array
8749
+ * @throws If indices are out of bounds
8750
+ */
8751
+ declare function safeSlice(data: Uint8Array, start: number, length?: number): Uint8Array;
8752
+ /**
8753
+ * Extract selector (first 4 bytes) from call data
8754
+ *
8755
+ * @param callData - The call data (Uint8Array or hex string)
8756
+ * @returns 4-byte selector
8757
+ * @throws If data is less than 4 bytes
8758
+ *
8759
+ * @example
8760
+ * ```ts
8761
+ * const selector = extractSelector(callData);
8762
+ * const selectorHex = bytesToHex(selector); // "0xdb20f9f5"
8763
+ * ```
8764
+ */
8765
+ declare function extractSelector(callData: Uint8Array | HexString$1): Uint8Array;
8766
+ /**
8767
+ * Extract selector as hex string from call data
8768
+ *
8769
+ * @param callData - The call data (Uint8Array or hex string)
8770
+ * @returns Hex string without 0x prefix (e.g., "db20f9f5")
8771
+ *
8772
+ * @example
8773
+ * ```ts
8774
+ * const selectorHex = extractSelectorHex(callData);
8775
+ * if (selectorHex === "db20f9f5") {
8776
+ * // PSP22::transfer
8777
+ * }
8778
+ * ```
8779
+ */
8780
+ declare function extractSelectorHex(callData: Uint8Array | HexString$1): string;
8781
+ /**
8782
+ * Normalize a hex string (ensure 0x prefix, lowercase)
8783
+ *
8784
+ * @param hex - Hex string with or without 0x prefix
8785
+ * @returns Normalized hex string with 0x prefix
8786
+ */
8787
+ declare function normalizeHex(hex: string): HexString$1;
8788
+ /**
8789
+ * Convert a selector string (with or without 0x) to Uint8Array
8790
+ *
8791
+ * @param selector - Selector as hex string
8792
+ * @returns 4-byte Uint8Array
8793
+ */
8794
+ declare function selectorToBytes(selector: string): Uint8Array;
8795
+ //#endregion
8796
+ export { AbortedError, ArithmeticError, BLOCKS_PER_DAY, BLOCKS_PER_HOUR, BLOCKS_PER_MINUTE, BLOCKS_PER_WEEK, BalanceStatus, BalancesTypesReasons, ContractError, type ContractErrorType, ContractExecutionError, D9, D9Apis, D9CallData, D9Calls, D9Constants, D9DispatchError, D9Errors, D9Events, D9Extensions, D9Queries, D9ViewFns, D9WhitelistEntry, D9_BLOCK_TIME_MS, D9_DECIMALS, D9_SS58_PREFIX, D9_SYMBOL, D9_TOKEN, DecodeError, DigestItem, DispatchClass, EncodeError, FormatBalanceOptions, FormatDurationOptions, GrandpaEquivocation, GrandpaEvent, GrandpaStoredState, type HexString, LangError, MetadataError, MultiAddress, NetworkError, Phase, type PolkadotSigner, type SS58String, SessionEvent, SignerError, Sr25519Keypair, TimeoutError, TokenConfig, TransactionError, TransactionPaymentEvent, TransactionPaymentReleases, TransactionalError, USDT_DECIMALS, USDT_SYMBOL, USDT_TOKEN, WalletAccount, WhitelistEntriesByChain, WhitelistEntry, addressesEqual, blocksToMs, blocksUntil, bytesEqual, bytesToHex, concatBytes, index_d_exports as contracts, createAccountFromMnemonic, createAccountFromPrivateKey, createSr25519SignerFromKeypair, _allDescriptors as d9, estimateBlockAtTime, estimateTimeAtBlock, extractSelector, extractSelectorHex, formatBalance, formatBlockDuration, formatTokenAmount, generateMnemonic, getAddressPrefix, getMetadata, hexToBytes, isContractError, isErrorType, isHexString, isValidAddress, isValidAddressForNetwork, isValidD9Address, mnemonicToMiniSecret, msToBlocks, normalizeHex, parseAmount, safeSlice, selectorToBytes, sr25519AddressFromKeypair, sr25519AddressFromSecretKeyHex, sr25519DeriveFromMiniSecret, sr25519KeypairFromMiniSecret, ss58DecodePublicKey, ss58Reencode, toD9Address, toNetworkAddress, validateMnemonic };
8720
8797
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -10630,5 +10630,111 @@ function formatBlockDuration(blocks, options = {}) {
10630
10630
  }
10631
10631
 
10632
10632
  //#endregion
10633
- export { AbortedError, ArithmeticError, BLOCKS_PER_DAY, BLOCKS_PER_HOUR, BLOCKS_PER_MINUTE, BLOCKS_PER_WEEK, BalanceStatus, BalancesTypesReasons, ContractError, ContractExecutionError, D9_BLOCK_TIME_MS, D9_DECIMALS, D9_SS58_PREFIX, D9_SYMBOL, D9_TOKEN, DecodeError, DigestItem, DispatchClass, EncodeError, GrandpaEquivocation, GrandpaEvent, GrandpaStoredState, LangError, MetadataError, MultiAddress, NetworkError, Phase, SessionEvent, SignerError, TimeoutError, TransactionError, TransactionPaymentEvent, TransactionPaymentReleases, TransactionalError, USDT_DECIMALS, USDT_SYMBOL, USDT_TOKEN, addressesEqual, blocksToMs, blocksUntil, bytesToHex, contracts_exports as contracts, createAccountFromMnemonic, createAccountFromPrivateKey, createSr25519SignerFromKeypair, d9_default as d9, estimateBlockAtTime, estimateTimeAtBlock, formatBalance, formatBlockDuration, formatTokenAmount, generateMnemonic, getAddressPrefix, getMetadata2 as getMetadata, hexToBytes, isContractError, isErrorType, isHexString, isValidAddress, isValidAddressForNetwork, isValidD9Address, mnemonicToMiniSecret, msToBlocks, parseAmount, sr25519AddressFromKeypair, sr25519AddressFromSecretKeyHex, sr25519DeriveFromMiniSecret, sr25519KeypairFromMiniSecret, ss58DecodePublicKey, ss58Reencode, toD9Address, toNetworkAddress, validateMnemonic };
10633
+ //#region src/utils/bytes.ts
10634
+ /**
10635
+ * Concatenate multiple Uint8Arrays into one
10636
+ *
10637
+ * @param arrays - Arrays to concatenate
10638
+ * @returns Combined Uint8Array
10639
+ *
10640
+ * @example
10641
+ * ```ts
10642
+ * const selector = hexToBytes("0xdb20f9f5");
10643
+ * const args = encodeArgs(...);
10644
+ * const callData = concatBytes(selector, args);
10645
+ * ```
10646
+ */
10647
+ function concatBytes(...arrays) {
10648
+ const totalLength = arrays.reduce((sum, arr$1) => sum + arr$1.length, 0);
10649
+ const result = new Uint8Array(totalLength);
10650
+ let offset = 0;
10651
+ for (const arr$1 of arrays) {
10652
+ result.set(arr$1, offset);
10653
+ offset += arr$1.length;
10654
+ }
10655
+ return result;
10656
+ }
10657
+ /**
10658
+ * Compare two Uint8Arrays for equality
10659
+ *
10660
+ * @param a - First array
10661
+ * @param b - Second array
10662
+ * @returns True if arrays are equal
10663
+ */
10664
+ function bytesEqual(a, b) {
10665
+ if (a.length !== b.length) return false;
10666
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
10667
+ return true;
10668
+ }
10669
+ /**
10670
+ * Extract a slice from a Uint8Array with bounds checking
10671
+ *
10672
+ * @param data - Source array
10673
+ * @param start - Start index
10674
+ * @param length - Optional length (defaults to rest of array)
10675
+ * @returns Sliced array
10676
+ * @throws If indices are out of bounds
10677
+ */
10678
+ function safeSlice(data, start, length) {
10679
+ if (start < 0 || start > data.length) throw new RangeError(`Start index ${start} out of bounds (0-${data.length})`);
10680
+ const end = length !== void 0 ? start + length : data.length;
10681
+ if (end > data.length) throw new RangeError(`End index ${end} exceeds array length ${data.length}`);
10682
+ return data.slice(start, end);
10683
+ }
10684
+ /**
10685
+ * Extract selector (first 4 bytes) from call data
10686
+ *
10687
+ * @param callData - The call data (Uint8Array or hex string)
10688
+ * @returns 4-byte selector
10689
+ * @throws If data is less than 4 bytes
10690
+ *
10691
+ * @example
10692
+ * ```ts
10693
+ * const selector = extractSelector(callData);
10694
+ * const selectorHex = bytesToHex(selector); // "0xdb20f9f5"
10695
+ * ```
10696
+ */
10697
+ function extractSelector(callData) {
10698
+ const bytes = callData instanceof Uint8Array ? callData : hexToBytes(callData);
10699
+ if (bytes.length < 4) throw new Error(`Call data too short (${bytes.length} bytes), need at least 4 bytes for selector`);
10700
+ return bytes.slice(0, 4);
10701
+ }
10702
+ /**
10703
+ * Extract selector as hex string from call data
10704
+ *
10705
+ * @param callData - The call data (Uint8Array or hex string)
10706
+ * @returns Hex string without 0x prefix (e.g., "db20f9f5")
10707
+ *
10708
+ * @example
10709
+ * ```ts
10710
+ * const selectorHex = extractSelectorHex(callData);
10711
+ * if (selectorHex === "db20f9f5") {
10712
+ * // PSP22::transfer
10713
+ * }
10714
+ * ```
10715
+ */
10716
+ function extractSelectorHex(callData) {
10717
+ return bytesToHex(extractSelector(callData)).slice(2);
10718
+ }
10719
+ /**
10720
+ * Normalize a hex string (ensure 0x prefix, lowercase)
10721
+ *
10722
+ * @param hex - Hex string with or without 0x prefix
10723
+ * @returns Normalized hex string with 0x prefix
10724
+ */
10725
+ function normalizeHex(hex$1) {
10726
+ return `0x${(hex$1.startsWith("0x") ? hex$1.slice(2) : hex$1).toLowerCase()}`;
10727
+ }
10728
+ /**
10729
+ * Convert a selector string (with or without 0x) to Uint8Array
10730
+ *
10731
+ * @param selector - Selector as hex string
10732
+ * @returns 4-byte Uint8Array
10733
+ */
10734
+ function selectorToBytes(selector) {
10735
+ return hexToBytes(normalizeHex(selector));
10736
+ }
10737
+
10738
+ //#endregion
10739
+ export { AbortedError, ArithmeticError, BLOCKS_PER_DAY, BLOCKS_PER_HOUR, BLOCKS_PER_MINUTE, BLOCKS_PER_WEEK, BalanceStatus, BalancesTypesReasons, ContractError, ContractExecutionError, D9_BLOCK_TIME_MS, D9_DECIMALS, D9_SS58_PREFIX, D9_SYMBOL, D9_TOKEN, DecodeError, DigestItem, DispatchClass, EncodeError, GrandpaEquivocation, GrandpaEvent, GrandpaStoredState, LangError, MetadataError, MultiAddress, NetworkError, Phase, SessionEvent, SignerError, TimeoutError, TransactionError, TransactionPaymentEvent, TransactionPaymentReleases, TransactionalError, USDT_DECIMALS, USDT_SYMBOL, USDT_TOKEN, addressesEqual, blocksToMs, blocksUntil, bytesEqual, bytesToHex, concatBytes, contracts_exports as contracts, createAccountFromMnemonic, createAccountFromPrivateKey, createSr25519SignerFromKeypair, d9_default as d9, estimateBlockAtTime, estimateTimeAtBlock, extractSelector, extractSelectorHex, formatBalance, formatBlockDuration, formatTokenAmount, generateMnemonic, getAddressPrefix, getMetadata2 as getMetadata, hexToBytes, isContractError, isErrorType, isHexString, isValidAddress, isValidAddressForNetwork, isValidD9Address, mnemonicToMiniSecret, msToBlocks, normalizeHex, parseAmount, safeSlice, selectorToBytes, sr25519AddressFromKeypair, sr25519AddressFromSecretKeyHex, sr25519DeriveFromMiniSecret, sr25519KeypairFromMiniSecret, ss58DecodePublicKey, ss58Reencode, toD9Address, toNetworkAddress, validateMnemonic };
10634
10740
  //# sourceMappingURL=index.mjs.map