@meshsdk/common 1.6.0-alpha.21 → 1.6.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 (84) hide show
  1. package/dist/index.cjs +1 -0
  2. package/dist/{index.d.mts → index.d.cts} +96 -8
  3. package/dist/index.d.ts +96 -8
  4. package/dist/index.js +1 -1316
  5. package/package.json +28 -9
  6. package/.turbo/turbo-build$colon$docs.log +0 -17
  7. package/.turbo/turbo-build$colon$mesh.log +0 -19
  8. package/.turbo/turbo-build.log +0 -19
  9. package/dist/index.mjs +0 -1189
  10. package/src/constants/cost-models.ts +0 -30
  11. package/src/constants/index.ts +0 -86
  12. package/src/constants/language-views.ts +0 -19
  13. package/src/constants/protocol-parameters.ts +0 -34
  14. package/src/constants/supported-wallets.ts +0 -12
  15. package/src/data/index.ts +0 -5
  16. package/src/data/json/aliases.ts +0 -218
  17. package/src/data/json/constructors.ts +0 -56
  18. package/src/data/json/credentials.ts +0 -77
  19. package/src/data/json/index.ts +0 -33
  20. package/src/data/json/primitives.ts +0 -154
  21. package/src/data/mesh/aliases.ts +0 -85
  22. package/src/data/mesh/constructors.ts +0 -68
  23. package/src/data/mesh/credentials.ts +0 -77
  24. package/src/data/mesh/index.ts +0 -4
  25. package/src/data/mesh/primitives.ts +0 -37
  26. package/src/data/parser.ts +0 -36
  27. package/src/data/time.ts +0 -92
  28. package/src/data/value.ts +0 -70
  29. package/src/index.ts +0 -7
  30. package/src/interfaces/evaluator.ts +0 -5
  31. package/src/interfaces/fetcher.ts +0 -31
  32. package/src/interfaces/index.ts +0 -7
  33. package/src/interfaces/initiator.ts +0 -9
  34. package/src/interfaces/listener.ts +0 -3
  35. package/src/interfaces/serializer.ts +0 -53
  36. package/src/interfaces/signer.ts +0 -12
  37. package/src/interfaces/submitter.ts +0 -3
  38. package/src/types/account-info.ts +0 -7
  39. package/src/types/action.ts +0 -15
  40. package/src/types/asset-extended.ts +0 -9
  41. package/src/types/asset-metadata.ts +0 -102
  42. package/src/types/asset.ts +0 -23
  43. package/src/types/block-info.ts +0 -17
  44. package/src/types/data-signature.ts +0 -4
  45. package/src/types/data.ts +0 -10
  46. package/src/types/deserialized/deserialized-address.ts +0 -6
  47. package/src/types/deserialized/deserialized-script.ts +0 -4
  48. package/src/types/deserialized/index.ts +0 -2
  49. package/src/types/era.ts +0 -1
  50. package/src/types/index.ts +0 -24
  51. package/src/types/message.ts +0 -4
  52. package/src/types/mint.ts +0 -12
  53. package/src/types/native-script.ts +0 -18
  54. package/src/types/network.ts +0 -7
  55. package/src/types/plutus-script.ts +0 -8
  56. package/src/types/pool-params.ts +0 -41
  57. package/src/types/protocol.ts +0 -22
  58. package/src/types/recipient.ts +0 -15
  59. package/src/types/relay.ts +0 -42
  60. package/src/types/token.ts +0 -3
  61. package/src/types/transaction-builder/data.ts +0 -31
  62. package/src/types/transaction-builder/index.ts +0 -73
  63. package/src/types/transaction-builder/mint.ts +0 -11
  64. package/src/types/transaction-builder/output.ts +0 -12
  65. package/src/types/transaction-builder/script.ts +0 -27
  66. package/src/types/transaction-builder/txin.ts +0 -46
  67. package/src/types/transaction-builder/withdrawal.ts +0 -207
  68. package/src/types/transaction-info.ts +0 -11
  69. package/src/types/utxo.ts +0 -16
  70. package/src/types/wallet.ts +0 -6
  71. package/src/utils/asset-fingerprint.ts +0 -11
  72. package/src/utils/bigNum.ts +0 -61
  73. package/src/utils/index.ts +0 -2
  74. package/test/data/json/aliases.test.ts +0 -135
  75. package/test/data/json/constructors.test.ts +0 -38
  76. package/test/data/json/credentials.test.ts +0 -84
  77. package/test/data/json/primitives.test.ts +0 -133
  78. package/test/data/mesh/aliases.test.ts +0 -45
  79. package/test/data/mesh/common.ts +0 -14
  80. package/test/data/mesh/constructors.test.ts +0 -53
  81. package/test/data/mesh/credentials.test.ts +0 -74
  82. package/test/data/mesh/primitives.test.ts +0 -41
  83. package/test/data/value.test.ts +0 -108
  84. package/tsconfig.json +0 -5
@@ -1,154 +0,0 @@
1
- import { PlutusData } from ".";
2
- import { ConStr0, conStr0, ConStr1, conStr1 } from "./constructors";
3
-
4
- /**
5
- * The Plutus Data boolean in JSON
6
- */
7
- export type Bool = ConStr0<[]> | ConStr1<[]>;
8
-
9
- /**
10
- * The Plutus Data byte string, representing in hex, in JSON
11
- */
12
- export type BuiltinByteString = { bytes: string };
13
-
14
- /**
15
- * The Plutus Data byte string, representing in hex, in JSON
16
- */
17
- export type ByteString = { bytes: string };
18
-
19
- /**
20
- * The Plutus Data integer in JSON
21
- */
22
- export type Integer = { int: number | bigint };
23
-
24
- /**
25
- * The Plutus Data list in JSON
26
- */
27
- export type List<T = any> = { list: T[] };
28
-
29
- /**
30
- * PlutusTx alias
31
- * The Plutus Data association map item in JSON
32
- */
33
- export type AssocMapItem<K, V> = { k: K; v: V };
34
-
35
- /**
36
- * The Plutus Data association map in JSON
37
- */
38
- export type AssocMap<K = any, V = any> = { map: AssocMapItem<K, V>[] };
39
-
40
- /**
41
- * The utility function to create a Plutus Data boolean in JSON
42
- * @param b boolean value
43
- * @returns The Plutus Data boolean object
44
- */
45
- export const bool = (b: boolean): Bool =>
46
- b ? conStr1<[]>([]) : conStr0<[]>([]);
47
-
48
- /**
49
- * The utility function to create a Plutus Data byte string in JSON
50
- * @param bytes The byte string in hex
51
- * @returns The Plutus Data byte string object
52
- */
53
- export const builtinByteString = (bytes: string): BuiltinByteString => {
54
- return byteString(bytes);
55
- };
56
-
57
- /**
58
- * The utility function to create a Plutus Data byte string in JSON
59
- * @param bytes The byte string in hex
60
- * @returns The Plutus Data byte string object
61
- */
62
- export const byteString = (bytes: string): ByteString => {
63
- // check if the string is a hex string with regex
64
- if (bytes.length % 2 !== 0) {
65
- throw new Error("Invalid hex string - odd length: " + bytes);
66
- }
67
- if (!/^[0-9a-fA-F]*$/.test(bytes)) {
68
- throw new Error("Invalid hex string - non-hex string character: " + bytes);
69
- }
70
- return {
71
- bytes,
72
- };
73
- };
74
-
75
- /**
76
- * The utility function to create a Plutus Data integer in JSON
77
- * @param int The integer value
78
- * @returns The Plutus Data integer object
79
- */
80
- export const integer = (int: number | bigint): Integer => ({ int });
81
-
82
- /**
83
- * The utility function to create a Plutus Data list in JSON
84
- * @param pList The list of Plutus Data
85
- * @param validation Default true - If current data construction would perform validation (introducing this flag due to possible performance issue in loop validation)
86
- * @returns The Plutus Data list object
87
- */
88
- export const list = <T = PlutusData>(
89
- pList: T[],
90
- validation = true,
91
- ): List<T> => {
92
- if (validation) {
93
- pList.forEach((item) => {
94
- if (typeof item !== "object") {
95
- throw new Error(
96
- "List item of JSON Cardano data type must be an object - " + item,
97
- );
98
- }
99
- });
100
- }
101
-
102
- return { list: pList };
103
- };
104
-
105
- /**
106
- * Converting a hex string into a ByteString Array, with max 32 bytes on each items
107
- * @param hexString The hex string to be converted into ByteString Array
108
- * @returns The ByteString Array representation of the hex string
109
- */
110
- export const stringToBSArray = (hexString: string): List<ByteString> => {
111
- const processRawStringIntoPlutusByteArray = (hexString: string): string[] => {
112
- const chunks = [];
113
- for (let i = 0; i < hexString.length; i += 64) {
114
- const chunk = hexString.substring(i, i + 64);
115
- chunks.push(chunk);
116
- }
117
- return chunks;
118
- };
119
-
120
- return list(
121
- processRawStringIntoPlutusByteArray(hexString).map(builtinByteString),
122
- );
123
- };
124
-
125
- /**
126
- * Converting ByteString Array into a single string
127
- * @param bsArray The ByteString Array to be converted into a single string
128
- * @returns The string representation of the ByteString Array
129
- */
130
- export const plutusBSArrayToString = (bsArray: List<ByteString>): string => {
131
- return bsArray.list.map((bs) => bs.bytes).join("");
132
- };
133
-
134
- /**
135
- * The utility function to create a Plutus Data association map in JSON
136
- * @param mapItems The items map in array
137
- * @param validation Default true - If current data construction would perform validation (introducing this flag due to possible performance issue in loop validation)
138
- * @returns The Plutus Data association map object
139
- */
140
- export const assocMap = <K, V>(
141
- mapItems: [K, V][],
142
- validation = true,
143
- ): AssocMap<K, V> => ({
144
- map: mapItems.map(([k, v]) => {
145
- if (validation) {
146
- if (typeof k !== "object" || typeof v !== "object") {
147
- throw new Error(
148
- `Map item of JSON Cardano data type must be an object - ${k}, ${v}`,
149
- );
150
- }
151
- }
152
- return { k, v };
153
- }),
154
- });
@@ -1,85 +0,0 @@
1
- import { POLICY_ID_LENGTH } from "../../constants";
2
- import { Data } from "../../types";
3
- import { mConStr0, MConStr0 } from "./constructors";
4
-
5
- /**
6
- * PlutusTx alias
7
- * The Mesh Data asset class
8
- */
9
- export type MAssetClass = MConStr0<[string, string]>;
10
-
11
- /**
12
- * Aiken alias
13
- * The Mesh Data output reference
14
- */
15
- export type MOutputReference = MConStr0<[MConStr0<[string]>, number]>;
16
-
17
- /**
18
- * PlutusTx alias
19
- * The Mesh Data TxOutRef
20
- */
21
- export type MTxOutRef = MConStr0<[MConStr0<[string]>, number]>;
22
-
23
- /**
24
- * Aiken alias
25
- * The Mesh Data tuple
26
- */
27
- export type MTuple<K, V> = [K, V];
28
-
29
- /**
30
- * The utility function to create a Mesh Data asset class
31
- * @param currencySymbolHex The currency symbol in hex
32
- * @param tokenNameHex The token name in hex
33
- * @returns The Mesh Data asset class object
34
- */
35
- export const mAssetClass = (
36
- currencySymbolHex: string,
37
- tokenNameHex: string,
38
- ): MAssetClass => {
39
- if (currencySymbolHex.length !== 56 && currencySymbolHex !== "") {
40
- throw new Error(
41
- `Invalid policy id for [${currencySymbolHex}] - should be ${POLICY_ID_LENGTH} bytes long or empty string for lovelace`,
42
- );
43
- }
44
-
45
- if (tokenNameHex.length > 64) {
46
- throw new Error(
47
- `Invalid asset name for [${tokenNameHex}] - should be less than 32 bytes (64 hex length) long`,
48
- );
49
- }
50
-
51
- return mConStr0([currencySymbolHex, tokenNameHex]);
52
- };
53
-
54
- /**
55
- * The utility function to create a Mesh Data output reference in Mesh Data type
56
- * @param txHash The transaction hash
57
- * @param index The index of the output
58
- * @returns The Mesh Data output reference object
59
- */
60
- export const mOutputReference = (
61
- txHash: string,
62
- index: number,
63
- ): MOutputReference => {
64
- if (txHash.length !== 64) {
65
- throw new Error("Invalid transaction hash - should be 32 bytes long");
66
- }
67
- return mConStr0([mConStr0([txHash]), index]);
68
- };
69
-
70
- /**
71
- * The utility function to create a Mesh Data TxOutRef in Mesh Data type
72
- * @param txHash The transaction hash
73
- * @param index The index of the output
74
- * @returns The Mesh Data TxOutRef object
75
- */
76
- export const mTxOutRef = (txHash: string, index: number): MTxOutRef =>
77
- mOutputReference(txHash, index);
78
-
79
- /**
80
- * The utility function to create a Mesh Data tuple in Mesh Data type
81
- * @param key The key of the tuple
82
- * @param value The value of the tuple
83
- * @returns The Mesh Data tuple object
84
- */
85
- export const mTuple = <K, V>(key: K, value: V): MTuple<K, V> => [key, value];
@@ -1,68 +0,0 @@
1
- import { Data } from "../../types";
2
-
3
- /**
4
- * The Mesh Data constructor object, representing custom data type
5
- */
6
- export type MConStr<T = any> = { alternative: number; fields: T };
7
-
8
- /**
9
- * The Mesh Data index 0 constructor object, representing custom data type
10
- */
11
- export type MConStr0<T = any> = MConStr<T>;
12
-
13
- /**
14
- * The Mesh Data index 1 constructor object, representing custom data type
15
- */
16
- export type MConStr1<T = any> = MConStr<T>;
17
-
18
- /**
19
- * The Mesh Data index 2 constructor object, representing custom data type
20
- */
21
- export type MConStr2<T = any> = MConStr<T>;
22
-
23
- /**
24
- * The utility function to create a Mesh Data constructor object, representing custom data type
25
- * @param alternative The constructor index number
26
- * @param fields The items in array
27
- * @returns The Mesh Data constructor object
28
- */
29
- export const mConStr = <T extends Data[]>(
30
- alternative: number,
31
- fields: T,
32
- ): MConStr<T> => ({
33
- alternative,
34
- fields,
35
- });
36
-
37
- /**
38
- * The utility function to create a Mesh Data index 0 constructor object, representing custom data type
39
- * @param alternative The constructor index number
40
- * @param fields The items in array
41
- * @returns The Mesh Data constructor object
42
- */
43
- export const mConStr0 = <T extends Data[]>(fields: T): MConStr0<T> => ({
44
- alternative: 0,
45
- fields,
46
- });
47
-
48
- /**
49
- * The utility function to create a Mesh Data index 1 constructor object, representing custom data type
50
- * @param alternative The constructor index number
51
- * @param fields The items in array
52
- * @returns The Mesh Data constructor object
53
- */
54
- export const mConStr1 = <T extends Data[]>(fields: T): MConStr1<T> => ({
55
- alternative: 1,
56
- fields,
57
- });
58
-
59
- /**
60
- * The utility function to create a Mesh Data index 2 constructor object, representing custom data type
61
- * @param alternative The constructor index number
62
- * @param fields The items in array
63
- * @returns The Mesh Data constructor object
64
- */
65
- export const mConStr2 = <T extends Data[]>(fields: T): MConStr2<T> => ({
66
- alternative: 2,
67
- fields,
68
- });
@@ -1,77 +0,0 @@
1
- import { Data } from "../../types";
2
- import { mConStr0, MConStr0, mConStr1, MConStr1 } from "./constructors";
3
-
4
- /**
5
- * The Mesh Data staking credential
6
- */
7
- export type MMaybeStakingHash =
8
- | MConStr1<[]>
9
- | MConStr0<[MConStr0<[MConStr0<[string]>]>]>
10
- | MConStr0<[MConStr0<[MConStr1<[string]>]>]>;
11
-
12
- /**
13
- * The Mesh Data public key address
14
- */
15
- export type MPubKeyAddress = MConStr0<[MConStr0<[string]>, MMaybeStakingHash]>;
16
-
17
- /**
18
- * The Mesh Data script address
19
- */
20
- export type MScriptAddress = MConStr0<[MConStr1<[string]>, MMaybeStakingHash]>;
21
-
22
- /**
23
- * The utility function to create a Mesh Data staking hash
24
- * @param stakeCredential The staking credential in hex
25
- * @param isScriptCredential The flag to indicate if the credential is a script credential
26
- * @returns The Mesh Data staking hash object
27
- */
28
- export const mMaybeStakingHash = (
29
- stakeCredential: string,
30
- isScriptCredential = false,
31
- ): MMaybeStakingHash => {
32
- if (stakeCredential === "") {
33
- return mConStr1<[]>([]);
34
- }
35
- if (isScriptCredential) {
36
- return mConStr0([mConStr0([mConStr1([stakeCredential])])]) as MConStr0<
37
- [MConStr0<[MConStr1<[string]>]>]
38
- >;
39
- }
40
- return mConStr0([mConStr0([mConStr0([stakeCredential])])]) as MConStr0<
41
- [MConStr0<[MConStr1<[string]>]>]
42
- >;
43
- };
44
-
45
- /**
46
- * The utility function to create a Mesh Data public key address
47
- * @param bytes The public key hash in hex
48
- * @param stakeCredential The staking credential in hex
49
- * @param isScriptCredential The flag to indicate if the credential is a script credential
50
- * @returns The Mesh Data public key address object
51
- */
52
- export const mPubKeyAddress = (
53
- bytes: string,
54
- stakeCredential?: string,
55
- isScriptCredential = false,
56
- ): Data =>
57
- mConStr0([
58
- { alternative: 0, fields: [bytes] },
59
- mMaybeStakingHash(stakeCredential || ""),
60
- ]);
61
-
62
- /**
63
- * The utility function to create a Mesh Data script address
64
- * @param bytes The validator hash in hex
65
- * @param stakeCredential The staking credential in hex
66
- * @param isScriptCredential The flag to indicate if the credential is a script credential
67
- * @returns The Mesh Data script address object
68
- */
69
- export const mScriptAddress = (
70
- bytes: string,
71
- stakeCredential?: string,
72
- isScriptCredential = false,
73
- ): Data =>
74
- mConStr0([
75
- { alternative: 1, fields: [bytes] },
76
- mMaybeStakingHash(stakeCredential || ""),
77
- ]);
@@ -1,4 +0,0 @@
1
- export * from "./aliases";
2
- export * from "./constructors";
3
- export * from "./credentials";
4
- export * from "./primitives";
@@ -1,37 +0,0 @@
1
- import { MConStr0, mConStr0, MConStr1, mConStr1 } from "./constructors";
2
-
3
- /**
4
- * The Mesh Data boolean
5
- */
6
- export type MBool = MConStr0<[]> | MConStr1<[]>;
7
-
8
- /**
9
- * The utility function to create a Mesh Data boolean
10
- * @param b boolean value
11
- * @returns The Mesh Data boolean object
12
- */
13
- export const mBool = (b: boolean): MBool =>
14
- b ? mConStr1<[]>([]) : mConStr0<[]>([]);
15
-
16
- /**
17
- * Converting a hex string into a BuiltinByteString Array, with max 32 bytes on each items
18
- * @param hexString The hex string to be converted into BuiltinByteString Array
19
- * @returns The BuiltinByteString Array representation of the hex string
20
- */
21
- export const mStringToPlutusBSArray = (hexString: string): string[] => {
22
- const chunks = [];
23
- for (let i = 0; i < hexString.length; i += 64) {
24
- const chunk = hexString.substring(i, i + 64);
25
- chunks.push(chunk);
26
- }
27
- return chunks;
28
- };
29
-
30
- /**
31
- * Converting BuiltinByteString Array into a single string
32
- * @param bsArray The BuiltinByteString Array to be converted into a single string
33
- * @returns The string representation of the BuiltinByteString Array
34
- */
35
- export const mPlutusBSArrayToString = (bsArray: string[]): string => {
36
- return bsArray.join("");
37
- };
@@ -1,36 +0,0 @@
1
- import { POLICY_ID_LENGTH } from "../constants";
2
-
3
- export const bytesToHex = (bytes: ArrayBuffer) =>
4
- Buffer.from(bytes).toString("hex");
5
-
6
- export const hexToBytes = (hex: string) => Buffer.from(hex, "hex");
7
-
8
- export const stringToHex = (str: string) =>
9
- Buffer.from(str, "utf8").toString("hex");
10
-
11
- export const hexToString = (hex: string) =>
12
- Buffer.from(hex, "hex").toString("utf8");
13
-
14
- export const toBytes = (hex: string): Uint8Array => {
15
- if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
16
- return Buffer.from(hex, "hex");
17
-
18
- return Buffer.from(hex, "utf-8");
19
- };
20
-
21
- export const fromUTF8 = (utf8: string) => {
22
- if (utf8.length % 2 === 0 && /^[0-9A-F]*$/i.test(utf8)) return utf8;
23
- return bytesToHex(Buffer.from(utf8, "utf-8"));
24
- };
25
-
26
- export const toUTF8 = (hex: string) =>
27
- Buffer.from(hex, "hex").toString("utf-8");
28
-
29
- export const parseAssetUnit = (unit: string) => {
30
- const policyId = unit.slice(0, POLICY_ID_LENGTH);
31
- const assetName = unit.includes(".")
32
- ? fromUTF8(unit.split(".")[1] as string)
33
- : unit.slice(POLICY_ID_LENGTH);
34
-
35
- return { policyId, assetName };
36
- };
package/src/data/time.ts DELETED
@@ -1,92 +0,0 @@
1
- import { Network } from "../types";
2
-
3
- export type SlotConfig = {
4
- zeroTime: number;
5
- zeroSlot: number;
6
- slotLength: number; // number of milliseconds.
7
- startEpoch: number;
8
- epochLength: number;
9
- };
10
-
11
- // export const SUPPORTED_CLOCKS: Record<
12
- // Network,
13
- // [epoch: string, slot: string, systemStart: string, epochLength: string]
14
- // > = {
15
- // testnet: ["74", "1598400", "1595967616", "432000"],
16
- // preview: ["183", "15811222", "1682467200", "86400"],
17
- // preprod: ["65", "26438400", "1682121600", "432000"],
18
- // mainnet: ["208", "4492800", "1596059091", "432000"],
19
- // };
20
-
21
- export const SLOT_CONFIG_NETWORK: Record<Network, SlotConfig> = {
22
- mainnet: {
23
- zeroTime: 1596059091000,
24
- zeroSlot: 4492800,
25
- slotLength: 1000,
26
- startEpoch: 208,
27
- epochLength: 432000,
28
- }, // Starting at Shelley era
29
- preview: {
30
- zeroTime: 1666656000000,
31
- zeroSlot: 0,
32
- slotLength: 1000,
33
- startEpoch: 183,
34
- epochLength: 86400,
35
- }, // Starting at Shelley era
36
- preprod: {
37
- zeroTime: 1654041600000 + 1728000000,
38
- zeroSlot: 86400,
39
- slotLength: 1000,
40
- startEpoch: 65,
41
- epochLength: 432000,
42
- }, // Starting at Shelley era
43
- /** Customizable slot config (Initialized with 0 values). */
44
- testnet: {
45
- zeroTime: 0,
46
- zeroSlot: 0,
47
- slotLength: 0,
48
- startEpoch: 0,
49
- epochLength: 0,
50
- },
51
- };
52
-
53
- export const slotToBeginUnixTime = (
54
- slot: number,
55
- slotConfig: SlotConfig,
56
- ): number => {
57
- const msAfterBegin = (slot - slotConfig.zeroSlot) * slotConfig.slotLength;
58
- return slotConfig.zeroTime + msAfterBegin;
59
- };
60
-
61
- export const unixTimeToEnclosingSlot = (
62
- unixTime: number,
63
- slotConfig: SlotConfig,
64
- ): number => {
65
- const timePassed = unixTime - slotConfig.zeroTime;
66
- const slotsPassed = Math.floor(timePassed / slotConfig.slotLength);
67
- return slotsPassed + slotConfig.zeroSlot;
68
- };
69
-
70
- export const resolveSlotNo = (
71
- network: Network,
72
- milliseconds = Date.now(),
73
- ): string => {
74
- return unixTimeToEnclosingSlot(
75
- milliseconds,
76
- SLOT_CONFIG_NETWORK[network],
77
- ).toString();
78
- };
79
-
80
- export const resolveEpochNo = (
81
- network: Network,
82
- milliseconds = Date.now(),
83
- ): number => {
84
- const config = SLOT_CONFIG_NETWORK[network];
85
-
86
- const msBigInt = BigInt(milliseconds);
87
- const epoch =
88
- (msBigInt / 1000n - BigInt(config.zeroTime)) / BigInt(config.epochLength) +
89
- BigInt(config.startEpoch);
90
-
91
- return Number(epoch);
92
- };
package/src/data/value.ts DELETED
@@ -1,70 +0,0 @@
1
- /**
2
- * It is suggested to keep the value representation as map of map,
3
- * where first key as policy id, second key as asset name, and final value as quantity.
4
- */
5
-
6
- import { Asset } from "../types";
7
- import {
8
- assocMap,
9
- AssocMap,
10
- CurrencySymbol,
11
- currencySymbol,
12
- Integer,
13
- integer,
14
- TokenName,
15
- tokenName,
16
- } from "./json";
17
-
18
- export type Value = AssocMap<CurrencySymbol, AssocMap<TokenName, Integer>>;
19
-
20
- export type MValue = Map<string, Map<string, bigint>>;
21
-
22
- export const value = (assets: Asset[]): Value => {
23
- const valueMapToParse: [CurrencySymbol, AssocMap<TokenName, Integer>][] = [];
24
- const valueMap: { [key: string]: { [key: string]: number } } = {};
25
-
26
- assets.forEach((asset) => {
27
- const sanitizedName = asset.unit.replace("lovelace", "");
28
- const policy = sanitizedName.slice(0, 56) || "";
29
- const token = sanitizedName.slice(56) || "";
30
-
31
- if (!valueMap[policy]) {
32
- valueMap[policy] = {};
33
- }
34
-
35
- if (!valueMap[policy]![token]) {
36
- valueMap[policy]![token] = Number(asset.quantity);
37
- } else {
38
- valueMap[policy]![token] += Number(asset.quantity);
39
- }
40
- });
41
-
42
- Object.keys(valueMap).forEach((policy) => {
43
- const policyByte = currencySymbol(policy);
44
- const tokens: [TokenName, Integer][] = Object.keys(valueMap[policy]!).map(
45
- (name) => [tokenName(name), integer(valueMap[policy]![name]!)],
46
- );
47
-
48
- const policyMap = assocMap(tokens);
49
- valueMapToParse.push([policyByte, policyMap]);
50
- });
51
-
52
- return assocMap(valueMapToParse);
53
- };
54
-
55
- export const parsePlutusValueToAssets = (plutusValue: Value): Asset[] => {
56
- const assets: Asset[] = [];
57
-
58
- plutusValue.map.forEach((policyMap) => {
59
- const policy = policyMap.k.bytes;
60
- policyMap.v.map.forEach((tokenMap) => {
61
- const token = tokenMap.k.bytes;
62
- const quantity = tokenMap.v.int.toString();
63
- const unsanitizedUnit = policy + token;
64
- const unit = unsanitizedUnit === "" ? "lovelace" : unsanitizedUnit;
65
- assets.push({ unit, quantity });
66
- });
67
- });
68
-
69
- return assets;
70
- };
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from "./constants";
2
- export * from "./interfaces";
3
- export * from "./types";
4
- export * from "./data";
5
- export * from "./utils";
6
-
7
- export { generateMnemonic, mnemonicToEntropy } from "bip39";
@@ -1,5 +0,0 @@
1
- import { Action } from "../types";
2
-
3
- export interface IEvaluator {
4
- evaluateTx(tx: string): Promise<Omit<Action, "data">[]>;
5
- }
@@ -1,31 +0,0 @@
1
- import type {
2
- AccountInfo,
3
- Asset,
4
- AssetMetadata,
5
- BlockInfo,
6
- Protocol,
7
- TransactionInfo,
8
- UTxO,
9
- } from "../types";
10
-
11
- /**
12
- * Fetcher interface defines end points to query blockchain data.
13
- */
14
- export interface IFetcher {
15
- fetchAccountInfo(address: string): Promise<AccountInfo>;
16
- fetchAddressUTxOs(address: string, asset?: string): Promise<UTxO[]>;
17
- fetchAssetAddresses(
18
- asset: string,
19
- ): Promise<{ address: string; quantity: string }[]>;
20
- fetchAssetMetadata(asset: string): Promise<AssetMetadata>;
21
- fetchBlockInfo(hash: string): Promise<BlockInfo>;
22
- fetchCollectionAssets(
23
- policyId: string,
24
- cursor?: number | string,
25
- ): Promise<{ assets: Asset[]; next?: string | number | null }>;
26
- fetchHandle(handle: string): Promise<object>;
27
- fetchHandleAddress(handle: string): Promise<string>;
28
- fetchProtocolParameters(epoch: number): Promise<Protocol>;
29
- fetchTxInfo(hash: string): Promise<TransactionInfo>;
30
- fetchUTxOs(hash: string): Promise<UTxO[]>;
31
- }
@@ -1,7 +0,0 @@
1
- export * from "./fetcher";
2
- export * from "./initiator";
3
- export * from "./listener";
4
- export * from "./submitter";
5
- export * from "./serializer";
6
- export * from "./signer";
7
- export * from "./evaluator";
@@ -1,9 +0,0 @@
1
- import { UTxO } from "../types";
2
-
3
- export interface IInitiator {
4
- getChangeAddress(): SometimesPromise<string>;
5
- getCollateral(): SometimesPromise<UTxO[]>;
6
- getUtxos(): SometimesPromise<UTxO[]>;
7
- }
8
-
9
- type SometimesPromise<T> = Promise<T> | T;