@talismn/scale 0.0.2 → 0.1.1

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 (52) hide show
  1. package/dist/declarations/src/index.d.ts +2 -3
  2. package/dist/declarations/src/papito.d.ts +6 -0
  3. package/dist/declarations/src/util/compactMetadata.d.ts +24 -0
  4. package/dist/declarations/src/util/decodeMetadata.d.ts +13 -0
  5. package/dist/declarations/src/util/decodeScale.d.ts +4 -0
  6. package/dist/declarations/src/util/encodeMetadata.d.ts +8 -0
  7. package/dist/declarations/src/util/encodeStateKey.d.ts +4 -0
  8. package/dist/declarations/src/util/getMetadataVersion.d.ts +6 -0
  9. package/dist/declarations/src/util/index.d.ts +7 -0
  10. package/dist/declarations/src/util/serdePapi.d.ts +30 -0
  11. package/dist/talismn-scale.cjs.dev.js +338 -1691
  12. package/dist/talismn-scale.cjs.prod.js +338 -1691
  13. package/dist/talismn-scale.esm.js +305 -1618
  14. package/package.json +16 -20
  15. package/CHANGELOG.md +0 -15
  16. package/dist/declarations/src/capi/crypto/base58.d.ts +0 -18
  17. package/dist/declarations/src/capi/crypto/hashers.d.ts +0 -67
  18. package/dist/declarations/src/capi/crypto/index.d.ts +0 -3
  19. package/dist/declarations/src/capi/crypto/ss58.d.ts +0 -16
  20. package/dist/declarations/src/capi/crypto/util/index.d.ts +0 -4
  21. package/dist/declarations/src/capi/crypto/util/nosimd.d.ts +0 -19
  22. package/dist/declarations/src/capi/crypto/util/simd.d.ts +0 -1
  23. package/dist/declarations/src/capi/frame_metadata/Extrinsic.d.ts +0 -50
  24. package/dist/declarations/src/capi/frame_metadata/FrameMetadata.d.ts +0 -61
  25. package/dist/declarations/src/capi/frame_metadata/decodeMetadata.d.ts +0 -312
  26. package/dist/declarations/src/capi/frame_metadata/index.d.ts +0 -4
  27. package/dist/declarations/src/capi/frame_metadata/key_codecs.d.ts +0 -27
  28. package/dist/declarations/src/capi/frame_metadata/raw/v14.d.ts +0 -312
  29. package/dist/declarations/src/capi/index.d.ts +0 -4
  30. package/dist/declarations/src/capi/scale_info/index.d.ts +0 -4
  31. package/dist/declarations/src/capi/scale_info/overrides/ChainError.d.ts +0 -26
  32. package/dist/declarations/src/capi/scale_info/overrides/Era.d.ts +0 -33
  33. package/dist/declarations/src/capi/scale_info/overrides/index.d.ts +0 -1
  34. package/dist/declarations/src/capi/scale_info/overrides/overrides.d.ts +0 -23
  35. package/dist/declarations/src/capi/scale_info/raw/Ty.d.ts +0 -313
  36. package/dist/declarations/src/capi/scale_info/transformTys.d.ts +0 -34
  37. package/dist/declarations/src/capi/util/index.d.ts +0 -3
  38. package/dist/declarations/src/capi/util/key.d.ts +0 -22
  39. package/dist/declarations/src/capi/util/normalize.d.ts +0 -25
  40. package/dist/declarations/src/capi/util/state.d.ts +0 -25
  41. package/dist/declarations/src/metadata/index.d.ts +0 -2
  42. package/dist/declarations/src/metadata/util.d.ts +0 -10
  43. package/dist/declarations/src/storage/getShape.d.ts +0 -15
  44. package/dist/declarations/src/storage/getTypeName.d.ts +0 -25
  45. package/dist/declarations/src/storage/index.d.ts +0 -11
  46. package/dist/declarations/src/suppressPortableRegistryConsoleWarnings.d.ts +0 -1
  47. package/dist/nosimd-18c022ec.cjs.dev.js +0 -46
  48. package/dist/nosimd-8c31fb2d.esm.js +0 -43
  49. package/dist/nosimd-b32b4901.cjs.prod.js +0 -46
  50. package/dist/simd-133b8f48.cjs.prod.js +0 -14
  51. package/dist/simd-2ddb8d7c.cjs.dev.js +0 -14
  52. package/dist/simd-b794dbff.esm.js +0 -1
@@ -1,3 +1,2 @@
1
- export * from "./capi";
2
- export * from "./metadata";
3
- export * from "./storage";
1
+ export * from "./papito";
2
+ export * from "./util";
@@ -0,0 +1,6 @@
1
+ export { getDynamicBuilder, getLookupFn } from "@polkadot-api/metadata-builders";
2
+ export type { V14, V15, V15Extrinsic, Codec, Binary } from "@polkadot-api/substrate-bindings";
3
+ export { toHex, fromHex } from "@polkadot-api/utils";
4
+ /** Constant: https://docs.substrate.io/build/application-development/#metadata-format */
5
+ export declare const magicNumber = 1635018093;
6
+ export { v14, v15, metadata } from "@polkadot-api/substrate-bindings";
@@ -0,0 +1,24 @@
1
+ import { V14, V15 } from "../papito";
2
+ export type V14Type = V14["lookup"][0];
3
+ export type V14Pallet = V14["pallets"][0];
4
+ export type V14StorageItem = NonNullable<V14Pallet["storage"]>["items"][0];
5
+ export type V15Type = V15["lookup"][0];
6
+ export type V15Pallet = V15["pallets"][0];
7
+ export type V15StorageItem = NonNullable<V15Pallet["storage"]>["items"][0];
8
+ /**
9
+ * Converts a `Metadata` into a `MiniMetadata`.
10
+ *
11
+ * A `MiniMetadata` only contains the types inside of its `lookup` which are relevant for
12
+ * the storage queries specified in `palletsAndItems`.
13
+ *
14
+ * E.g. if `palletsAndItems` is `{ pallet: "System", items: ["Account"] }`, then only the
15
+ * types used in the `System.Account` storage query will remain inside of metadata.lookups.
16
+ */
17
+ export declare const compactMetadata: (metadata: V15 | V14, palletsAndItems?: Array<{
18
+ pallet: string;
19
+ constants?: string[];
20
+ items: string[];
21
+ }>, runtimeApisAndMethods?: Array<{
22
+ runtimeApi: string;
23
+ methods: string[];
24
+ }>, extraKeepTypes?: number[]) => void;
@@ -0,0 +1,13 @@
1
+ import { V14, V15 } from "@polkadot-api/substrate-bindings";
2
+ export declare const decodeMetadata: (metadataRpc: string) => {
3
+ metadataVersion: number;
4
+ } & ({
5
+ metadata: V15;
6
+ tag: "v15";
7
+ } | {
8
+ metadata: V14;
9
+ tag: "v14";
10
+ } | {
11
+ metadata?: undefined;
12
+ tag?: undefined;
13
+ });
@@ -0,0 +1,4 @@
1
+ import { getDynamicBuilder } from "@polkadot-api/metadata-builders";
2
+ type ScaleStorageCoder = ReturnType<ReturnType<typeof getDynamicBuilder>["buildStorage"]>;
3
+ export declare const decodeScale: <T>(scaleCoder: ScaleStorageCoder | undefined, change: string | null, error?: string) => T | null;
4
+ export {};
@@ -0,0 +1,8 @@
1
+ import { V14, V15 } from "@polkadot-api/substrate-bindings";
2
+ export declare const encodeMetadata: ({ metadata, tag, }: {
3
+ metadata: V15;
4
+ tag: "v15";
5
+ } | {
6
+ metadata: V14;
7
+ tag: "v14";
8
+ }) => string;
@@ -0,0 +1,4 @@
1
+ import { getDynamicBuilder } from "@polkadot-api/metadata-builders";
2
+ type ScaleStorageCoder = ReturnType<ReturnType<typeof getDynamicBuilder>["buildStorage"]>;
3
+ export declare const encodeStateKey: (scaleCoder: ScaleStorageCoder | undefined, error?: string, ...args: any[]) => string | undefined;
4
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Extracts the `version` u8 from a SCALE-encoded metadata blob and returns it as a `number`.
3
+ *
4
+ * Only reads the first 40 bytes of the blob.
5
+ */
6
+ export declare const getMetadataVersion: (metadataRpc: string | Uint8Array | ArrayBuffer) => number;
@@ -0,0 +1,7 @@
1
+ export * from "./compactMetadata";
2
+ export * from "./decodeMetadata";
3
+ export * from "./decodeScale";
4
+ export * from "./encodeMetadata";
5
+ export * from "./encodeStateKey";
6
+ export * from "./getMetadataVersion";
7
+ export * from "./serdePapi";
@@ -0,0 +1,30 @@
1
+ /**
2
+ * For the substrate-tokens (and other) modules, we configure the `onChainId` field in chaindata to tell the module how to query each token.
3
+ * These queries are made to the tokens pallet.
4
+ * E.g. api.query.Tokens.Account(accountAddress, papiParse(onChainId))
5
+ *
6
+ * The `onChainId` field on chaindata must be a JSON-parseable string, but for some SCALE types (especially the Binary type) we must
7
+ * use specific `polkadot-api` classes to handle SCALE-encoding the statekey.
8
+ *
9
+ * Some examples:
10
+ * Input: `5`
11
+ * Output: `5`
12
+ *
13
+ * Input: `{ type: "DexShare", value: [ { type: "Token", value: { type: "ACA" } }, { type: "Token", value: { type: "AUSD" } } ] }`
14
+ * Output: `Enum("DexShare", [Enum("Token", Enum("ACA")), Enum("Token", Enum("AUSD"))])`
15
+ *
16
+ * Input: `{ type: "LiquidCrowdloan", value: 13 }`
17
+ * Output: `Enum("LiquidCrowdloan", 13)`
18
+ *
19
+ * Input: `{ type: "NativeToken", value: "bigint:2" }`
20
+ * Output: `Enum("NativeToken", 2n)`
21
+ *
22
+ * Input: `{ type: "Erc20", value: "hex:0x07df96d1341a7d16ba1ad431e2c847d978bc2bce" }`
23
+ * Output: `Enum("Erc20", Binary.fromHex("0x07df96d1341a7d16ba1ad431e2c847d978bc2bce"))`
24
+ *
25
+ * Input: `{ type: "Stellar", value: { code: "bin:TZS", issuer: "hex:0x34c94b2a4ba9e8b57b22547dcbb30f443c4cb02da3829a89aa1bd4780e4466ba" } }`
26
+ * Output: `Enum("Stellar", { code: Binary.fromText("TZS"), issuer: Binary.fromHex("0x34c94b2a4ba9e8b57b22547dcbb30f443c4cb02da3829a89aa1bd4780e4466ba") })`
27
+ */
28
+ export declare const papiParse: <T = unknown>(text: string | T) => T;
29
+ export declare const papiStringify: (value: any, // eslint-disable-line @typescript-eslint/no-explicit-any
30
+ space?: string | number) => string;