@tezos-x/octez.js-utils 0.9.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"octez.js-utils.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @description base58 name to prefix mapping
3
+ */
4
+ export declare enum PrefixV2 {
5
+ BlockHash = "B",
6
+ OperationHash = "o",
7
+ OperationListHash = "Lo",
8
+ OperationListListHash = "LLo",
9
+ ProtocolHash = "P",
10
+ ContextHash = "Co",
11
+ BlockMetadataHash = "bm",
12
+ OperationMetadataHash = "r",
13
+ OperationMetadataListHash = "Lr",
14
+ OperationMetadataListListHash = "LLr",
15
+ Ed25519PublicKeyHash = "tz1",
16
+ Secp256k1PublicKeyHash = "tz2",
17
+ P256PublicKeyHash = "tz3",
18
+ ContractHash = "KT1",
19
+ BlindedPublicKeyHash = "btz1",
20
+ BLS12_381PublicKeyHash = "tz4",
21
+ TXRollupAddress = "txr1",
22
+ ZkRollupHash = "epx1",
23
+ ScRollupHash = "scr1",
24
+ SmartRollupHash = "sr1",
25
+ CryptoboxPublicKeyHash = "id",
26
+ Ed25519Seed = "edsk",
27
+ Ed25519PublicKey = "edpk",
28
+ Secp256k1SecretKey = "spsk",
29
+ P256SecretKey = "p2sk",
30
+ BLS12_381SecretKey = "BLsk",
31
+ ValueHash = "vh",
32
+ CycleNonce = "nce",
33
+ ScriptExpr = "expr",
34
+ InboxHash = "txi",
35
+ MessageHash = "txm",
36
+ CommitmentHash = "txc",
37
+ MessageResultHash = "txmr",
38
+ MessageResultListHash = "txM",
39
+ WithdrawListHash = "txw",
40
+ ScRollupStateHash = "scs1",
41
+ ScRollupCommitmentHash = "scc1",
42
+ SmartRollupStateHash = "srs1",
43
+ SmartRollupCommitmentHash = "src1",
44
+ Ed25519EncryptedSeed = "edesk",
45
+ Secp256k1EncryptedSecretKey = "spesk",
46
+ P256EncryptedSecretKey = "p2esk",
47
+ BLS12_381EncryptedSecretKey = "BLesk",
48
+ Secp256k1EncryptedScalar = "seesk",
49
+ Secp256k1PublicKey = "sppk",
50
+ P256PublicKey = "p2pk",
51
+ Secp256k1Scalar = "SSp",
52
+ Secp256k1Element = "GSp",
53
+ Ed25519SecretKey = "_edsk",
54
+ Ed25519Signature = "edsig",
55
+ Secp256k1Signature = "spsig1",
56
+ P256Signature = "p2sig",
57
+ GenericSignature = "sig",
58
+ ChainID = "Net",
59
+ SaplingSpendingKey = "sask",
60
+ EncryptedSaplingSpendingKey = "_sask",
61
+ SaplingAddress = "zet1",
62
+ GenericAggregateSignature = "asig",
63
+ BLS12_381Signature = "BLsig",
64
+ BLS12_381PublicKey = "BLpk",
65
+ SlotHeader = "sh"
66
+ }
67
+ /**
68
+ * @description base58 prefix to bytes mapping
69
+ */
70
+ export declare const prefixV2: {
71
+ [key in PrefixV2]: Uint8Array;
72
+ };
73
+ /**
74
+ * @description base58 prefix to payload length mapping
75
+ */
76
+ export declare const payloadLength: {
77
+ [key in PrefixV2]: number;
78
+ };
@@ -0,0 +1,184 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module @tezos-x/octez.js-utils
4
+ */
5
+ import { Buffer } from 'buffer';
6
+ import { PrefixV2 } from './constants';
7
+ import BigNumber from 'bignumber.js';
8
+ /**
9
+ * @description list of prefixes that can be used to decode an address
10
+ */
11
+ export declare const addressPrefixes: PrefixV2[];
12
+ /**
13
+ * @description list of prefixes that can be used to decode a public key
14
+ */
15
+ export declare const publicKeyPrefixes: PrefixV2[];
16
+ /**
17
+ * @description list of prefixes that can be used to decode a public key hash
18
+ */
19
+ export declare const publicKeyHashPrefixes: PrefixV2[];
20
+ /**
21
+ * @description list of prefixes that can be used to decode a signature
22
+ */
23
+ export declare const signaturePrefixes: PrefixV2[];
24
+ /**
25
+ * @description Decodes Base58 string, looks for known prefix and strips it
26
+ * @param src Base58 string
27
+ * @returns Payload and prefix
28
+ * @example b58DecodeAndCheckPrefix('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM') // returns [Uint8Array, PrefixV2.Ed25519PublicKeyHash]
29
+ * @example b58DecodeAndCheckPrefix('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM', [PrefixV2.Ed25519PublicKeyHash]) // returns [Uint8Array, PrefixV2.Ed25519PublicKeyHash]
30
+ * @example b58DecodeAndCheckPrefix('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM', [PrefixV2.Ed25519PublicKeyHash], true) // returns Uint8Array
31
+ */
32
+ export declare function b58DecodeAndCheckPrefix<T extends readonly PrefixV2[]>(src: string, allowed?: T): [Uint8Array, T[number]];
33
+ export declare function b58DecodeAndCheckPrefix<T extends readonly PrefixV2[]>(src: string, allowed: T, payloadOnly: false): [Uint8Array, T[number]];
34
+ export declare function b58DecodeAndCheckPrefix<T extends readonly PrefixV2[]>(src: string, allowed: T, payloadOnly: true): Uint8Array;
35
+ /**
36
+ * @description Decode a Base58 public key and return its binary representation
37
+ * @param value Value to decode
38
+ * @param fmt optional format of the decoded return value, 'hex' or 'array'
39
+ * @returns string or Uint8Array of bytes
40
+ * @example b58DecodePublicKey('edpkuNjKKT48xBoT5asPrWdmuM1Yw8D93MwgFgVvtca8jb5pstzaCh') // return '0060842d4ba23a9940ef5dcf4404fdaa430cfaaccb5029fad06cb5ea894e4562ae'
41
+ */
42
+ export declare function b58DecodePublicKey(value: string, fmt?: 'hex'): string;
43
+ export declare function b58DecodePublicKey(value: string, fmt: 'array'): Uint8Array;
44
+ /**
45
+ * @description Decode a Base58 public key hash and return its binary representation
46
+ * @param value Value to decode
47
+ * @param fmt optional format of the decoded return value, 'hex' or 'array'
48
+ * @returns string or Uint8Array of bytes
49
+ * @example b58DecodePublicKeyHash('tz2MVED1t9Jery77Bwm1m5YhUx8Wp5KWWRQe') // return '0001907d6a7e9f084df840d6e67ffa8db5464f87d4d1'
50
+ */
51
+ export declare function b58DecodePublicKeyHash(value: string, fmt?: 'hex'): string;
52
+ export declare function b58DecodePublicKeyHash(value: string, fmt: 'array'): Uint8Array;
53
+ /**
54
+ * @description Decode a Base58 string and assert tz4 type
55
+ * @param value a bls address(tz4) to decode
56
+ * @param fmt optional format of the decoded return value, 'hex' or 'array'
57
+ * @returns string or Uint8Array of bytes
58
+ * @example b58DecodeBlsAddress('tz4QyWfEiv56CVDATV3DT3CDVhPaMKif2Ce8') // return 'af2dc3c40667abc0e89c0ef40171d22aed08d5eb'
59
+ */
60
+ export declare function b58DecodeBlsAddress(value: string, fmt?: 'hex'): string;
61
+ export declare function b58DecodeBlsAddress(value: string, fmt: 'array'): Uint8Array;
62
+ /**
63
+ * @description Decode a Base58 contract ID and return its binary representation
64
+ * @param value Value to decode
65
+ * @param fmt optional format of the decoded return value, 'hex' or 'array'
66
+ * @returns string or Uint8Array of bytes
67
+ * @example b58DecodeAddress('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM') // return '0000e96b9f8b19af9c7ffa0c0480e1977b295850961f'
68
+ */
69
+ export declare function b58DecodeAddress(value: string, fmt?: 'hex'): string;
70
+ export declare function b58DecodeAddress(value: string, fmt: 'array'): Uint8Array;
71
+ /**
72
+ * @description Gets Tezos address (PKH) from Public Key
73
+ * @param publicKey Base58 Public Key
74
+ * @returns A string of the Tezos address (PKH) that was derived from the given Public Key
75
+ * @example getPkhfromPk('edpkuNjKKT48xBoT5asPrWdmuM1Yw8D93MwgFgVvtca8jb5pstzaCh') // return 'tz2MVED1t9Jery77Bwm1m5YhUx8Wp5KWWRQe'
76
+ */
77
+ export declare function getPkhfromPk(publicKey: string): string;
78
+ /**
79
+ * @description Add the prefix to a hex string or Uint8Array and Base58 encode it
80
+ * @param value Value to Base58 encode
81
+ * @param pre prefix ID to append to the encoded string
82
+ * @example b58Encode('e96b9f8b19af9c7ffa0c0480e1977b295850961f', PrefixV2.Ed25519PublicKeyHash) // returns 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM'
83
+ */
84
+ export declare function b58Encode(value: string | Uint8Array, pre: PrefixV2): string;
85
+ /**
86
+ * @description Parse binary public key and return Base58 representation
87
+ * @param value Binary key data
88
+ * @returns return prefixed public key
89
+ * @example encodeKey('02033aba7da4a2e7b5dd9f074555c118829aff16213ea1b65859686bd5fcfeaf3616') // return 'p2pk66xmhjiN7LpfrDGFwpxPtJxkLtPjQ6HUxJbKmRbxSR7RMpamDwi'
90
+ */
91
+ export declare function encodeKey(value: string | Uint8Array): string;
92
+ /**
93
+ * @description Parse binary public key hash and return Base58 representation
94
+ * @param value Key hash to parse
95
+ * @returns return prefixed public key hash
96
+ * @example encodeKeyHash('0001907d6a7e9f084df840d6e67ffa8db5464f87d4d1') // return 'tz2MVED1t9Jery77Bwm1m5YhUx8Wp5KWWRQe'
97
+ */
98
+ export declare function encodeKeyHash(value: string | Uint8Array): string;
99
+ /**
100
+ * @description Parse binary Contract ID and return Base58 representation
101
+ * @param value Address to parse (tz1, tz2, tz3, KT1, or sr1).
102
+ * @example encodeAddress('0000e96b9f8b19af9c7ffa0c0480e1977b295850961f') // return 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM'
103
+ */
104
+ export declare function encodeAddress(value: string | Uint8Array): string;
105
+ /**
106
+ * @description Base58 encode an address without predefined prefix
107
+ * @param value Address to base58 encode (tz4) hex dec
108
+ * @returns return address
109
+ * @example encodeBlsAddress('af2dc3c40667abc0e89c0ef40171d22aed08d5eb') // return 'tz4QyWfEiv56CVDATV3DT3CDVhPaMKif2Ce8'
110
+ */
111
+ export declare function encodeBlsAddress(value: string): string;
112
+ /**
113
+ * @description convert a fragment of Michelson code in hex string to an 'expr' prefix + base58 encoded BLAKE2b hash string
114
+ * @param value a fragment of Michelson code in hex string
115
+ * @returns return 'expr' prefix + base58 encoded BLAKE2b hash
116
+ * @example encodeExpr('050a000000160000b2e19a9e74440d86c59f13dab8a18ff873e889ea') // return 'exprv6UsC1sN3Fk2XfgcJCL8NCerP5rCGy1PRESZAqr7L2JdzX55EN'
117
+ */
118
+ export declare function encodeExpr(value: string): string;
119
+ /**
120
+ * @description convert a signed operation in hex string to an 'op' prefix + base58 encoded BLAKE2b hash string
121
+ * @param value signed operation in hex string
122
+ * @returns return 'op' prefix + base58 encoded BLAKE2b hash
123
+ * @example encodeOpHash('0f185d8a30061e8134c162dbb7a6c3ab8f5fdb153363ccd6149b49a33481156a6c00b2e19a9e74440d86c59f13dab8a18ff873e889eaa304ab05da13000001f1585a7384f36e45fb43dc37e8ce172bced3e05700ff0000000002002110c033f3a990c2e46a3d6054ecc2f74072aae7a34b5ac4d9ce9edc11c2410a97695682108951786f05b361da03b97245dc9897e1955e08b5b8d9e153b0bdeb0d') // return 'opapqvVXmebRTCFd2GQFydr4tJj3V5QocQuTmuhbatcHm4Seo2t'
124
+ */
125
+ export declare function encodeOpHash(value: string): string;
126
+ /**
127
+ * @description Convert an hex string to a Uint8Array
128
+ * @param hex Hex string to convert
129
+ * @throws {@link ValueConversionError}
130
+ */
131
+ export declare function hex2buf(hex: string): Uint8Array;
132
+ /**
133
+ * @description Merge 2 buffers together
134
+ * @param b1 First buffer
135
+ * @param b2 Second buffer
136
+ */
137
+ export declare function mergebuf(b1: Uint8Array, b2: Uint8Array): Uint8Array;
138
+ /**
139
+ * @description Flatten a michelson json representation to an array
140
+ * @param s michelson json
141
+ */
142
+ export declare function mic2arr(s: any): any;
143
+ /**
144
+ * @description Convert a Uint8Array to an hex string
145
+ * @param buffer Uint8Array to convert
146
+ */
147
+ export declare function buf2hex(bytes: ArrayLike<number>): string;
148
+ /**
149
+ * @description Convert a string to a byte string representation
150
+ * @param str String to convert
151
+ */
152
+ export declare function stringToBytes(str: string): string;
153
+ /**
154
+ * @description Convert byte string representation to string
155
+ * @param hex byte string to convert
156
+ */
157
+ export declare function bytesToString(hex: string): string;
158
+ /**
159
+ * @description Convert hex string/UintArray/Buffer to bytes
160
+ * @param hex String value to convert to bytes
161
+ */
162
+ export declare function hex2Bytes(hex: string): Buffer;
163
+ /**
164
+ * @description Converts a number or Bignumber to hexadecimal string
165
+ * @param val The value that will be converted to a hexadecimal string value
166
+ */
167
+ export declare function toHexBuf(val: number | BigNumber, bitLength?: number): Buffer;
168
+ export declare function numToHexBuffer(val: number | BigNumber, bitLength?: number): Buffer;
169
+ /**
170
+ * @description Converts a number or BigNumber to a padded hexadecimal string
171
+ * @param val The value that will be converted into a padded hexadecimal string value
172
+ * @param bitLength The length of bits
173
+ *
174
+ */
175
+ export declare function num2PaddedHex(val: number | BigNumber, bitLength?: number): string;
176
+ /**
177
+ *
178
+ * @description Strips the first 2 characters of a hex string (0x)
179
+ *
180
+ * @param hex string to strip prefix from
181
+ */
182
+ export declare function stripHexPrefix(hex: string): string;
183
+ export declare function splitAddress(addr: string): [string, string | null];
184
+ export declare function compareArrays(a: ArrayLike<number>, b: ArrayLike<number>): number;
@@ -0,0 +1,20 @@
1
+ import { ParameterValidationError, UnsupportedActionError, ValidationResult } from '@tezos-x/octez.js-core';
2
+ export { InvalidAddressError, InvalidBlockHashError, InvalidHexStringError, InvalidMessageError, InvalidKeyError, InvalidPublicKeyError, InvalidSignatureError, InvalidContractAddressError, InvalidChainIdError, InvalidKeyHashError, InvalidOperationHashError, InvalidOperationKindError, DeprecationError, ProhibitedActionError, } from '@tezos-x/octez.js-core';
3
+ /**
4
+ * @category Error
5
+ * @description Error that indicates invalid protocol hash being passed or used
6
+ */
7
+ export declare class InvalidProtocolHashError extends ParameterValidationError {
8
+ readonly protocolHash: string;
9
+ name: string;
10
+ constructor(protocolHash: string, errorDetails?: string | ValidationResult);
11
+ }
12
+ /**
13
+ * @category Error
14
+ * @description Error that indicates unable to convert data type from one to another
15
+ */
16
+ export declare class ValueConversionError extends UnsupportedActionError {
17
+ readonly value: string;
18
+ readonly desiredType: string;
19
+ constructor(value: string, desiredType: string);
20
+ }
@@ -0,0 +1,4 @@
1
+ import BigNumber from 'bignumber.js';
2
+ type Format = 'tz' | 'mtz' | 'mutez';
3
+ export declare function format(from: Format | undefined, to: Format | undefined, amount: number | string | BigNumber): string | number | BigNumber;
4
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module @tezos-x/octez.js-utils
4
+ */
5
+ export * from './encoding';
6
+ export * from './validators';
7
+ export { VERSION } from './version';
8
+ export { PrefixV2, payloadLength } from './constants';
9
+ export { verifySignature, BLS12_381_DST, POP_DST } from './verify-signature';
10
+ export * from './errors';
11
+ export { format } from './format';
@@ -0,0 +1,167 @@
1
+ import { PrefixV2 } from './constants';
2
+ import { ValidationResult } from '@tezos-x/octez.js-core';
3
+ export { ValidationResult } from '@tezos-x/octez.js-core';
4
+ /**
5
+ * @description Used to check if a value has one of the allowed prefixes.
6
+ * @returns true if the value has one of the allowed prefixes, false otherwise
7
+ * @example
8
+ * ```
9
+ * import { isValidPrefixedValue } from '@tezos-x/octez.js-utils';
10
+ * const value = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
11
+ * const isValid = isValidPrefixedValue(value, [PrefixV2.Ed25519PublicKeyHash])
12
+ * console.log(isValid) // true
13
+ * ```
14
+ */
15
+ export declare function isValidPrefixedValue(value: string, prefixes?: PrefixV2[]): boolean;
16
+ /**
17
+ * @description Used to check if an address or a contract address is valid.
18
+ *
19
+ * @returns
20
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
21
+ *
22
+ * @example
23
+ * ```
24
+ * import { validateAddress } from '@tezos-x/octez.js-utils';
25
+ * const pkh = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
26
+ * const validation = validateAddress(pkh)
27
+ * console.log(validation)
28
+ * // This example return 3 which correspond to VALID
29
+ * ```
30
+ */
31
+ export declare function validateAddress(value: string): ValidationResult;
32
+ /**
33
+ * @description Used to check if a chain id is valid.
34
+ *
35
+ * @returns
36
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
37
+ *
38
+ * @example
39
+ * ```
40
+ * import { validateChain } from '@tezos-x/octez.js-utils';
41
+ * const chainId = 'NetXdQprcVkpaWU'
42
+ * const validation = validateChain(chainId)
43
+ * console.log(validation)
44
+ * // This example return 3 which correspond to VALID
45
+ * ```
46
+ */
47
+ export declare function validateChain(value: string): ValidationResult;
48
+ /**
49
+ * @description Used to check if a contract address is valid.
50
+ *
51
+ * @returns
52
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
53
+ *
54
+ * @example
55
+ * ```
56
+ * import { validateContractAddress } from '@tezos-x/octez.js-utils';
57
+ * const contractAddress = 'KT1JVErLYTgtY8uGGZ4mso2npTSxqVLDRVbC'
58
+ * const validation = validateContractAddress(contractAddress)
59
+ * console.log(validation)
60
+ * // This example return 3 which correspond to VALID
61
+ * ```
62
+ */
63
+ export declare function validateContractAddress(value: string): ValidationResult;
64
+ /**
65
+ * @description Used to check if a key hash is valid.
66
+ *
67
+ * @returns
68
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
69
+ *
70
+ * @example
71
+ * ```
72
+ * import { validateKeyHash } from '@tezos-x/octez.js-utils';
73
+ * const keyHashWithoutPrefix = '1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
74
+ * const validation = validateKeyHash(keyHashWithoutPrefix)
75
+ * console.log(validation)
76
+ * // This example return 0 which correspond to NO_PREFIX_MATCHED
77
+ * ```
78
+ */
79
+ export declare function validateKeyHash(value: string): ValidationResult;
80
+ /**
81
+ * @description Used to check if a signature is valid.
82
+ *
83
+ * @returns
84
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
85
+ *
86
+ * @example
87
+ * ```
88
+ * import { validateSignature } from '@tezos-x/octez.js-utils';
89
+ * const signature = 'edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg'
90
+ * const validation = validateSignature(signature)
91
+ * console.log(validation)
92
+ * // This example return 3 which correspond to VALID
93
+ * ```
94
+ */
95
+ export declare function validateSignature(value: string): ValidationResult;
96
+ /**
97
+ * @description Used to check if a public key is valid.
98
+ *
99
+ * @returns
100
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
101
+ *
102
+ * @example
103
+ * ```
104
+ * import { validatePublicKey } from '@tezos-x/octez.js-utils';
105
+ * const publicKey = 'edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g'
106
+ * const validation = validatePublicKey(publicKey)
107
+ * console.log(validation)
108
+ * // This example return 3 which correspond to VALID
109
+ * ```
110
+ */
111
+ export declare function validatePublicKey(value: string): ValidationResult;
112
+ /**
113
+ * @description Used to check if an operation hash is valid.
114
+ *
115
+ * @returns
116
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
117
+ *
118
+ * @example
119
+ * ```
120
+ * import { validateOperation } from '@tezos-x/octez.js-utils';
121
+ * const operationHash = 'oo6JPEAy8VuMRGaFuMmLNFFGdJgiaKfnmT1CpHJfKP3Ye5ZahiP'
122
+ * const validation = validateOperation(operationHash)
123
+ * console.log(validation)
124
+ * // This example return 3 which correspond to VALID
125
+ * ```
126
+ */
127
+ export declare function validateOperation(value: string): ValidationResult;
128
+ /**
129
+ * @description Used to check if a protocol hash is valid.
130
+ *
131
+ * @returns
132
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
133
+ *
134
+ * @example
135
+ * ```
136
+ * import { validateProtocol } from '@tezos-x/octez.js-utils';
137
+ * const protocolHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
138
+ * const validation = validateProtocol(protocolHash)
139
+ * console.log(validation)
140
+ * // This example return 3 which correspond to VALID
141
+ * ```
142
+ */
143
+ export declare function validateProtocol(value: string): ValidationResult;
144
+ /**
145
+ * @description Used to check if a block hash is valid.
146
+ *
147
+ * @returns
148
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
149
+ *
150
+ * @example
151
+ * ```
152
+ * import { validateBlock } from '@tezos-x/octez.js-utils';
153
+ * const blockHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
154
+ * const validation = validateBlock(blockHash)
155
+ * console.log(validation)
156
+ * // This example return 3 which correspond to VALID
157
+ * ```
158
+ */
159
+ export declare function validateBlock(value: string): ValidationResult;
160
+ /**
161
+ * @description Used to check if a spending key is valid.
162
+ * @returns
163
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
164
+ *
165
+ */
166
+ export declare function validateSpendingKey(value: string): ValidationResult;
167
+ export declare function validateSmartRollupAddress(value: string): ValidationResult;
@@ -0,0 +1,22 @@
1
+ export declare const BLS12_381_DST = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
2
+ export declare const POP_DST = "BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
3
+ /**
4
+ * @description Verify signature of a payload
5
+ * @param message The forged message including the magic byte (11 for block, 12 for preattestation, 13 for attestation, 3 for generic, 5 for the PACK format of michelson) in string or Uint8Array
6
+ * @param publicKey The public key to verify the signature against
7
+ * @param signature The signature to verify
8
+ * @param watermark Optional if not included in the message
9
+ * @param pop Optional if verifying proof of possession signature
10
+ * @returns A boolean indicating if the signature matches
11
+ * @throws {@link InvalidPublicKeyError} | {@link InvalidSignatureError} | {@link InvalidMessageError}
12
+ * @example
13
+ * ```
14
+ * const message = '03d0c10e3ed11d7c6e3357f6ef335bab9e8f2bd54d0ce20c482e241191a6e4b8ce6c01be917311d9ac46959750e405d57e268e2ed9e174a80794fbd504e12a4a000141eb3781afed2f69679ff2bbe1c5375950b0e40d00ff000000005e05050505050507070100000024747a32526773486e74516b72794670707352466261313652546656503539684b72654a4d07070100000024747a315a6672455263414c42776d4171776f6e525859565142445439426a4e6a42484a750001';
15
+ * const pk = 'sppk7c7hkPj47yjYFEHX85q46sFJGw6RBrqoVSHwAJAT4e14KJwzoey';
16
+ * const sig = 'spsig1cdLkp1RLgUHAp13aRFkZ6MQDPp7xCnjAExGL3MBSdMDmT6JgQSX8cufyDgJRM3sinFtiCzLbsyP6d365EHoNevxhT47nx'
17
+ *
18
+ * const response = verifySignature(message, pk, sig);
19
+ * ```
20
+ *
21
+ */
22
+ export declare function verifySignature(message: string | Uint8Array, publicKey: string, signature: string, watermark?: Uint8Array, pop?: boolean): boolean;
@@ -0,0 +1,4 @@
1
+ export declare const VERSION: {
2
+ commitHash: string;
3
+ version: string;
4
+ };
package/package.json ADDED
@@ -0,0 +1,106 @@
1
+ {
2
+ "name": "@tezos-x/octez.js-utils",
3
+ "version": "0.9.0",
4
+ "description": "converts michelson data and types into convenient JS/TS objects",
5
+ "keywords": [
6
+ "tezos",
7
+ "blockchain",
8
+ "michelson",
9
+ "smart-contract"
10
+ ],
11
+ "main": "dist/octez.js-utils.umd.js",
12
+ "module": "dist/octez.js-utils.es6.js",
13
+ "typings": "dist/types/octez.js-utils.d.ts",
14
+ "files": [
15
+ "dist",
16
+ "signature.json"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "author": "Simon Boissonneault-Robert <simon@ecadlabs.com>",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/trilitech/octez.js.git"
25
+ },
26
+ "license": "Apache-2.0",
27
+ "engines": {
28
+ "node": ">=20"
29
+ },
30
+ "scripts": {
31
+ "lint": "eslint --ext .js,.ts .",
32
+ "precommit": "lint-staged",
33
+ "prebuild": "rimraf dist",
34
+ "version-stamp": "node ../octez.js/version-stamping.js",
35
+ "build": "tsc --project ./tsconfig.prod.json --module commonjs && rollup -c rollup.config.ts --bundleConfigAsCjs",
36
+ "start": "rollup -c rollup.config.ts --bundleConfigAsCjs -w",
37
+ "test": "jest"
38
+ },
39
+ "lint-staged": {
40
+ "{src,test}/**/*.ts": [
41
+ "prettier --write",
42
+ "eslint --fix"
43
+ ]
44
+ },
45
+ "jest": {
46
+ "transform": {
47
+ ".(ts|tsx)": "ts-jest"
48
+ },
49
+ "testEnvironment": "node",
50
+ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
51
+ "moduleFileExtensions": [
52
+ "ts",
53
+ "tsx",
54
+ "js"
55
+ ],
56
+ "coveragePathIgnorePatterns": [
57
+ "/node_modules/",
58
+ "/test/"
59
+ ],
60
+ "collectCoverageFrom": [
61
+ "src/**/*.{js,ts}"
62
+ ]
63
+ },
64
+ "dependencies": {
65
+ "@noble/curves": "^1.9.7",
66
+ "@stablelib/blake2b": "^1.0.1",
67
+ "@stablelib/ed25519": "^1.0.3",
68
+ "@tezos-x/octez.js-core": "*",
69
+ "@types/bs58check": "^2.1.2",
70
+ "bignumber.js": "^9.1.2",
71
+ "blakejs": "^1.2.1",
72
+ "bs58check": "^3.0.1",
73
+ "buffer": "^6.0.3",
74
+ "typedarray-to-buffer": "^4.0.0"
75
+ },
76
+ "devDependencies": {
77
+ "@types/bluebird": "^3.5.42",
78
+ "@types/jest": "^29.5.12",
79
+ "@types/node": "^20",
80
+ "@types/typedarray-to-buffer": "^4.0.4",
81
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
82
+ "@typescript-eslint/parser": "^6.21.0",
83
+ "colors": "^1.4.0",
84
+ "coveralls": "^3.1.1",
85
+ "cross-env": "^7.0.3",
86
+ "eslint": "^8.57.0",
87
+ "jest": "^29.7.0",
88
+ "jest-config": "^29.7.0",
89
+ "lint-staged": "^15.2.7",
90
+ "lodash.camelcase": "^4.3.0",
91
+ "prettier": "^3.3.3",
92
+ "prompt": "^1.3.0",
93
+ "replace-in-file": "^8.1.0",
94
+ "rimraf": "^6.0.1",
95
+ "rollup": "^4.22.4",
96
+ "rollup-plugin-json": "^4.0.0",
97
+ "rollup-plugin-polyfill-node": "^0.13.0",
98
+ "rollup-plugin-typescript2": "^0.36.0",
99
+ "shelljs": "^0.8.5",
100
+ "ts-jest": "^29.2.3",
101
+ "ts-node": "^10.9.2",
102
+ "ts-toolbelt": "^9.6.0",
103
+ "typescript": "~5.5.4"
104
+ },
105
+ "gitHead": "551e35aeff7d6dcde1c72284238c0ed3c3aae77e"
106
+ }