@bitgo-beta/abstract-substrate 1.0.1-beta.20 → 1.0.1-beta.21

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,258 @@
1
+ import { DotAssetTypes, BaseUtils, DotAddressFormat, Seed } from '@bitgo-beta/sdk-core';
2
+ import { KeyringPair } from '@polkadot/keyring/types';
3
+ import { Args, BaseTxInfo, OptionsWithMeta, UnsignedTransaction } from '@substrate/txwrapper-core';
4
+ import { DecodedSignedTx, DecodedSigningPayload, TypeRegistry } from '@substrate/txwrapper-core/lib/types';
5
+ import { AddProxyBatchCallArgs, BatchArgs, BatchCallObject, HexString, ProxyArgs, StakeArgs, StakeBatchCallArgs, StakeMoreArgs, StakeMoreCallArgs, TransferAllArgs, TransferArgs, TxMethod, UnstakeBatchCallArgs } from './iface';
6
+ import { KeyPair } from '.';
7
+ export declare class Utils implements BaseUtils {
8
+ /** @inheritdoc */
9
+ isValidAddress(address: string): boolean;
10
+ /** @inheritdoc */
11
+ isValidBlockId(hash: string): boolean;
12
+ /** @inheritdoc */
13
+ isValidPrivateKey(key: string): boolean;
14
+ /** @inheritdoc */
15
+ isValidPublicKey(key: string): boolean;
16
+ /** @inheritdoc */
17
+ isValidSignature(signature: string): boolean;
18
+ /**
19
+ * Verifies the signature on a given message
20
+ *
21
+ * @param {string} signedMessage the signed message for the signature
22
+ * @param {string} signature the signature to verify
23
+ * @param {string} address the address of the signer
24
+ * @returns {boolean} whether the signature is valid or not
25
+ */
26
+ verifySignature(signedMessage: string, signature: string, address: string): boolean;
27
+ /** @inheritdoc */
28
+ isValidTransactionId(txId: string): boolean;
29
+ /**
30
+ * decodeSeed decodes a substrate seed
31
+ *
32
+ * @param {string} seed - the seed to be validated.
33
+ * @returns {Seed} - the object Seed
34
+ */
35
+ decodeSeed(seed: string): Seed;
36
+ /**
37
+ * Helper function to capitalize the first letter of a string
38
+ *
39
+ * @param {string} val
40
+ * @returns {string}
41
+ */
42
+ capitalizeFirstLetter(val: string): string;
43
+ /**
44
+ * Helper function to decode the internal method hex in case of a proxy transaction
45
+ *
46
+ * @param {string | UnsignedTransaction} tx
47
+ * @param { metadataRpc: string; registry: TypeRegistry } options
48
+ * @returns {TransferArgs}
49
+ */
50
+ decodeCallMethod(tx: string | UnsignedTransaction, options: {
51
+ metadataRpc: string;
52
+ registry: TypeRegistry;
53
+ }): TransferArgs;
54
+ /**
55
+ * keyPairFromSeed generates an object with secretKey and publicKey using the substrate sdk
56
+ * @param seed 32 bytes long seed
57
+ * @returns KeyPair
58
+ */
59
+ keyPairFromSeed(seed: Uint8Array): KeyPair;
60
+ /**
61
+ * Signing function. Implement this on the OFFLINE signing device.
62
+ *
63
+ * @param {KeyringPair} pair - The signing pair.
64
+ * @param {string} signingPayload - Payload to sign.
65
+ * @param {UnsignedTransaction} transaction - raw transaction to sign
66
+ * @param {Object} options
67
+ * @param {HexString} options.metadataRpc - metadata that is needed for substrate to sign
68
+ * @param {TypeRegistry} options.registry - metadata that is needed for substrate to sign
69
+ */
70
+ createSignedTx(pair: KeyringPair, signingPayload: string, transaction: UnsignedTransaction, options: {
71
+ metadataRpc: HexString;
72
+ registry: TypeRegistry;
73
+ }): string;
74
+ /**
75
+ * Serializes the signed transaction
76
+ *
77
+ * @param transaction Transaction to serialize
78
+ * @param signature Signature of the message
79
+ * @param metadataRpc Network metadata
80
+ * @param registry Transaction registry
81
+ * @returns string Serialized transaction
82
+ */
83
+ serializeSignedTransaction(transaction: any, signature: any, metadataRpc: `0x${string}`, registry: any): string;
84
+ /**
85
+ * Decodes the substrate address from the given format
86
+ *
87
+ * @param {string} address
88
+ * @param {number} [ss58Format]
89
+ * @returns {string}
90
+ */
91
+ decodeSubstrateAddress(address: string, ss58Format: number): string;
92
+ /**
93
+ * Decodes the substrate address from the given format
94
+ *
95
+ * @param {string} address
96
+ * @param {number} [ss58Format]
97
+ * @returns {string}
98
+ */
99
+ encodeSubstrateAddress(address: string, ss58Format?: number): string;
100
+ /**
101
+ * Retrieves the txHash of a signed txHex
102
+ *
103
+ * @param txHex signed transaction hex
104
+ * @returns {string}
105
+ */
106
+ getTxHash(txHex: string): string;
107
+ isSigningPayload(payload: DecodedSigningPayload | DecodedSignedTx): payload is DecodedSigningPayload;
108
+ isProxyTransfer(arg: TxMethod['args']): arg is ProxyArgs;
109
+ isTransfer(arg: TxMethod['args']): arg is TransferArgs;
110
+ isTransferAll(arg: TxMethod['args']): arg is TransferAllArgs;
111
+ /**
112
+ * Returns true if arg is of type BatchArgs, false otherwise.
113
+ *
114
+ * @param arg The object to test.
115
+ *
116
+ * @return true if arg is of type BatchArgs, false otherwise.
117
+ */
118
+ isBatch(arg: TxMethod['args']): arg is BatchArgs;
119
+ /**
120
+ * Returns true if arg is of type BatchArgs and the calls of the batch are staking calls: a stake
121
+ * call (bond) followed by an add proxy call (addProxy), false otherwise.
122
+ *
123
+ * @param arg The object to test.
124
+ *
125
+ * @return true if arg is of type BatchArgs and the calls of the batch are staking calls: a stake
126
+ * call (bond) followed by an add proxy call (addProxy), false otherwise.
127
+ */
128
+ isStakingBatch(arg: TxMethod['args']): arg is BatchArgs;
129
+ /**
130
+ * Returns true if arg is of type StakeBatchCallArgs, false otherwise.
131
+ *
132
+ * @param arg The object to test.
133
+ *
134
+ * @return true if arg is of type StakeBatchCallArgs, false otherwise.
135
+ */
136
+ isStakeBatchCallArgs(arg: BatchCallObject['args']): arg is StakeBatchCallArgs;
137
+ /**
138
+ * Returns true if arg is of type AddProxyBatchCallArgs, false otherwise.
139
+ *
140
+ * @param arg The object to test.
141
+ *
142
+ * @return true if arg is of type AddProxyBatchCallArgs, false otherwise.
143
+ */
144
+ isAddProxyBatchCallArgs(arg: BatchCallObject['args']): arg is AddProxyBatchCallArgs;
145
+ /**
146
+ * Returns true if arg is of type BatchArgs and the calls of the batch are unstaking calls: a remove
147
+ * proxy call (removeProxy), followed by a chill call, and an unstake call (unbond), false otherwise.
148
+ *
149
+ * @param arg The object to test.
150
+ *
151
+ * @return true if arg is of type BatchArgs and the calls of the batch are unstaking calls: a remove
152
+ * proxy call (removeProxy), followed by a chill call, and an unstake call (unbond), false otherwise.
153
+ */
154
+ isUnstakingBatch(arg: TxMethod['args']): arg is BatchArgs;
155
+ /**
156
+ * Returns true if arg is of type AddProxyBatchCallArgs, false otherwise.
157
+ *
158
+ * @param arg The object to test.
159
+ *
160
+ * @return true if arg is of type AddProxyBatchCallArgs, false otherwise.
161
+ */
162
+ isRemoveProxyBatchCallArgs(arg: BatchCallObject['args']): arg is AddProxyBatchCallArgs;
163
+ /**
164
+ * Returns true if arg is of type UnstakeBatchCallArgs, false otherwise.
165
+ *
166
+ * @param arg The object to test.
167
+ *
168
+ * @return true if arg is of type UnstakeBatchCallArgs, false otherwise.
169
+ */
170
+ isUnstakeBatchCallArgs(arg: BatchCallObject['args']): arg is UnstakeBatchCallArgs;
171
+ /**
172
+ * Returns true if arg is of type StakeArgs, false otherwise.
173
+ *
174
+ * @param arg The object to test.
175
+ *
176
+ * @return true if arg is of type StakeArgs, false otherwise.
177
+ */
178
+ isBond(arg: TxMethod['args']): arg is StakeArgs;
179
+ /**
180
+ * Returns true if arg is of type StakeMoreArgs, false otherwise.
181
+ *
182
+ * @param arg The object to test.
183
+ *
184
+ * @return true if arg is of type StakeMoreArgs, false otherwise.
185
+ */
186
+ isBondExtra(arg: TxMethod['args'] | BatchCallObject['args']): arg is StakeMoreArgs;
187
+ /**
188
+ * Returns true if arg is of type StakeMoreArgs, false otherwise.
189
+ *
190
+ * @param arg The object to test.
191
+ *
192
+ * @return true if arg is of type StakeMoreArgs, false otherwise.
193
+ */
194
+ isBondBatchExtra(arg: BatchCallObject['args']): arg is StakeMoreCallArgs;
195
+ /**
196
+ * extracts and returns the signature in hex format given a raw signed transaction
197
+ *
198
+ * @param {string} rawTx signed raw transaction
199
+ * @param options registry substrate registry used to retrieve the signature
200
+ */
201
+ recoverSignatureFromRawTx(rawTx: string, options: {
202
+ registry: TypeRegistry;
203
+ }): string;
204
+ /**
205
+ * Decodes the dot address from the given format
206
+ *
207
+ * @param {string} address
208
+ * @param {number} [ss58Format]
209
+ * @returns {KeyPair}
210
+ */
211
+ decodeSubstrateAddressToKeyPair(address: string, ss58Format?: number): KeyPair;
212
+ /**
213
+ * Checks whether the given input is a hex string with with 0 value
214
+ * used to check whether a given transaction is immortal or mortal
215
+ * @param hexValue
216
+ */
217
+ isZeroHex(hexValue: string): boolean;
218
+ /**
219
+ * Takes an asset name and returns the respective address to format to
220
+ * since substrate addresses differ depending on the network
221
+ * @param networkCoinName
222
+ */
223
+ getAddressFormat(networkCoinName: DotAssetTypes): DotAddressFormat;
224
+ /**
225
+ * Creates a pure proxy extrinsic. Substrate has renamed anonymous proxies to pure proxies, but
226
+ * the libraries we are using to build transactions have not been updated, as a stop gap we are
227
+ * defining the pure proxy extrinsic here.
228
+ *
229
+ * @param args Arguments to the createPure extrinsic.
230
+ * @param info Common information to all transactions.
231
+ * @param options Chain registry and metadata.
232
+ */
233
+ pureProxy(args: PureProxyArgs, info: BaseTxInfo, options: OptionsWithMeta): UnsignedTransaction;
234
+ /**
235
+ * Removes '0x' from a given `string` if present.
236
+ *
237
+ * @param {string} str the string value.
238
+ *
239
+ * @return {string} a string without a '0x' prefix.
240
+ */
241
+ stripHexPrefix(str: string): string;
242
+ /**
243
+ * Returns true if a string starts with '0x', false otherwise.
244
+ *
245
+ * @param {string} str the string value.
246
+ *
247
+ * @return {boolean} true if a string starts with '0x', false otherwise.
248
+ */
249
+ isHexPrefixed(str: string): boolean;
250
+ }
251
+ interface PureProxyArgs extends Args {
252
+ proxyType: string;
253
+ delay: number;
254
+ index: number;
255
+ }
256
+ declare const utils: Utils;
257
+ export default utils;
258
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,E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