@bitgo/sdk-coin-stx 1.1.0-rc.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.
Files changed (54) hide show
  1. package/.eslintignore +5 -0
  2. package/.mocharc.yml +8 -0
  3. package/CHANGELOG.md +11 -0
  4. package/LICENSE +191 -0
  5. package/README.md +30 -0
  6. package/dist/src/index.d.ts +5 -0
  7. package/dist/src/index.d.ts.map +1 -0
  8. package/dist/src/index.js +30 -0
  9. package/dist/src/lib/abstractContractBuilder.d.ts +19 -0
  10. package/dist/src/lib/abstractContractBuilder.d.ts.map +1 -0
  11. package/dist/src/lib/abstractContractBuilder.js +70 -0
  12. package/dist/src/lib/constants.d.ts +8 -0
  13. package/dist/src/lib/constants.d.ts.map +1 -0
  14. package/dist/src/lib/constants.js +19 -0
  15. package/dist/src/lib/contractBuilder.d.ts +33 -0
  16. package/dist/src/lib/contractBuilder.d.ts.map +1 -0
  17. package/dist/src/lib/contractBuilder.js +116 -0
  18. package/dist/src/lib/iface.d.ts +48 -0
  19. package/dist/src/lib/iface.d.ts.map +1 -0
  20. package/dist/src/lib/iface.js +3 -0
  21. package/dist/src/lib/index.d.ts +6 -0
  22. package/dist/src/lib/index.d.ts.map +1 -0
  23. package/dist/src/lib/index.js +33 -0
  24. package/dist/src/lib/keyPair.d.ts +55 -0
  25. package/dist/src/lib/keyPair.d.ts.map +1 -0
  26. package/dist/src/lib/keyPair.js +140 -0
  27. package/dist/src/lib/sendmanyBuilder.d.ts +23 -0
  28. package/dist/src/lib/sendmanyBuilder.d.ts.map +1 -0
  29. package/dist/src/lib/sendmanyBuilder.js +75 -0
  30. package/dist/src/lib/transaction.d.ts +49 -0
  31. package/dist/src/lib/transaction.d.ts.map +1 -0
  32. package/dist/src/lib/transaction.js +225 -0
  33. package/dist/src/lib/transactionBuilder.d.ts +86 -0
  34. package/dist/src/lib/transactionBuilder.d.ts.map +1 -0
  35. package/dist/src/lib/transactionBuilder.js +263 -0
  36. package/dist/src/lib/transactionBuilderFactory.d.ts +30 -0
  37. package/dist/src/lib/transactionBuilderFactory.d.ts.map +1 -0
  38. package/dist/src/lib/transactionBuilderFactory.js +81 -0
  39. package/dist/src/lib/transferBuilder.d.ts +30 -0
  40. package/dist/src/lib/transferBuilder.d.ts.map +1 -0
  41. package/dist/src/lib/transferBuilder.js +99 -0
  42. package/dist/src/lib/utils.d.ts +207 -0
  43. package/dist/src/lib/utils.d.ts.map +1 -0
  44. package/dist/src/lib/utils.js +503 -0
  45. package/dist/src/stx.d.ts +56 -0
  46. package/dist/src/stx.d.ts.map +1 -0
  47. package/dist/src/stx.js +196 -0
  48. package/dist/src/tstx.d.ts +16 -0
  49. package/dist/src/tstx.d.ts.map +1 -0
  50. package/dist/src/tstx.js +24 -0
  51. package/dist/src/types.d.ts +34 -0
  52. package/dist/src/types.d.ts.map +1 -0
  53. package/dist/src/types.js +3 -0
  54. package/package.json +62 -0
@@ -0,0 +1,207 @@
1
+ /// <reference types="node" />
2
+ import { AddressHashMode, AddressVersion, ClarityValue, StacksTransaction } from '@stacks/transactions';
3
+ import { AddressDetails, SendParams } from './iface';
4
+ import { KeyPair } from '.';
5
+ import { StacksNetwork as BitgoStacksNetwork } from '@bitgo/statics';
6
+ /**
7
+ * Encodes a buffer as a "0x" prefixed lower-case hex string.
8
+ *
9
+ * @param {Buffer} buff - a buffer with a hexadecimal string
10
+ * @returns {string} - the hexadecimal string prefixed with "0x"
11
+ */
12
+ export declare function bufferToHexPrefixString(buff: Buffer): string;
13
+ /**
14
+ * Remove the "0x" prefix from the given string, if present.
15
+ *
16
+ * @param {string} hex - a hexadecimal string
17
+ * @returns {string} - the hexadecimal string without a leading "0x"
18
+ */
19
+ export declare function removeHexPrefix(hex: string): string;
20
+ /**
21
+ * @param tx
22
+ */
23
+ export declare function getTxSenderAddress(tx: StacksTransaction): string;
24
+ /**
25
+ * Returns whether or not the string is a valid amount number
26
+ *
27
+ * @param {string} amount - the string to validate
28
+ * @returns {boolean} - the validation result
29
+ */
30
+ export declare function isValidAmount(amount: string): boolean;
31
+ /**
32
+ * Returns whether or not the string is a valid protocol address
33
+ *
34
+ * @param {string} address - the address to be validated
35
+ * @returns {boolean} - the validation result
36
+ */
37
+ export declare function isValidAddress(address: string): boolean;
38
+ /**
39
+ * Returns whether or not the string is a valid protocol transaction id or not.
40
+ *
41
+ * A valid transaction id is a SHA-512/256 hash of a serialized transaction; see
42
+ * the txidFromData function in @stacks/transaction:
43
+ * https://github.com/blockstack/stacks.js/blob/master/packages/transactions/src/utils.ts#L97
44
+ *
45
+ * @param {string} txId - the transaction id to be validated
46
+ * @returns {boolean} - the validation result
47
+ */
48
+ export declare function isValidTransactionId(txId: string): boolean;
49
+ /**
50
+ * Returns whether or not the string is a valid protocol public key or
51
+ * extended public key.
52
+ *
53
+ * The key format is documented at
54
+ * https://github.com/stacksgov/sips/blob/main/sips/sip-005/sip-005-blocks-and-transactions.md#transaction-authorization
55
+ *
56
+ * @param {string} pub - the public key to be validated
57
+ * @returns {boolean} - the validation result
58
+ */
59
+ export declare function isValidPublicKey(pub: string): boolean;
60
+ /**
61
+ * Returns whether or not the string is a valid protocol private key, or extended
62
+ * private key.
63
+ *
64
+ * The protocol key format is described in the @stacks/transactions npm package, in the
65
+ * createStacksPrivateKey function:
66
+ * https://github.com/blockstack/stacks.js/blob/master/packages/transactions/src/keys.ts#L125
67
+ *
68
+ * @param {string} prv - the private key (or extended private key) to be validated
69
+ * @returns {boolean} - the validation result
70
+ */
71
+ export declare function isValidPrivateKey(prv: string): boolean;
72
+ /**
73
+ * Checks if raw transaction can be deserialized
74
+ *
75
+ * @param {unknown} rawTransaction - transaction in raw hex format
76
+ * @returns {boolean} - the validation result
77
+ */
78
+ export declare function isValidRawTransaction(rawTransaction: unknown): boolean;
79
+ /**
80
+ * Returns whether or not the memo string is valid
81
+ *
82
+ * @param {string} memo - the string to be validated
83
+ * @returns {boolean} - the validation result
84
+ */
85
+ export declare function isValidMemo(memo: string): boolean;
86
+ /**
87
+ * Checks for valid contract address
88
+ *
89
+ * @param {string} addr - contract deployer address
90
+ * @param {BitgoStacksNetwork} network - network object
91
+ * @returns {boolean} - the validation result
92
+ */
93
+ export declare function isValidContractAddress(addr: string, network: BitgoStacksNetwork): boolean;
94
+ /**
95
+ * Check if the name is one of valid contract names
96
+ *
97
+ * @param {string} name - function name
98
+ * @returns {boolean} - validation result
99
+ */
100
+ export declare function isValidContractFunctionName(name: string): boolean;
101
+ /**
102
+ * Unpads a memo string, so it removes nulls.
103
+ *
104
+ * Useful when memo is fill up the length. Result is becomes readable.
105
+ *
106
+ * @param {string} memo - the string to be validated
107
+ * @returns {boolean} - the validation result
108
+ */
109
+ export declare function unpadMemo(memo: string): string;
110
+ /**
111
+ * Generate a multisig address from multiple STX public keys
112
+ *
113
+ * @param {string[]} pubKeys - list of public keys as strings
114
+ * @param {AddressVersion} addressVersion - MainnetMultiSig, TestnetMultiSig
115
+ * @param {AddressHashMode} addressHashMode - SerializeP2SH
116
+ * @param {number} [signaturesRequired] - number of signatures required, default value its 2
117
+ * @returns {address: string, hash160: string} - a multisig address
118
+ */
119
+ export declare function getSTXAddressFromPubKeys(pubKeys: string[], addressVersion?: AddressVersion, addressHashMode?: AddressHashMode, signaturesRequired?: number): {
120
+ address: string;
121
+ hash160: string;
122
+ };
123
+ /**
124
+ * signs a string message
125
+ *
126
+ * @param keyPair
127
+ * @param data - message to be signed
128
+ * @returns signed message string
129
+ */
130
+ export declare function signMessage(keyPair: KeyPair, data: string): string;
131
+ /**
132
+ * Verifies a signed message
133
+ *
134
+ * The signature must be 130 bytes long -- see RECOVERABLE_ECDSA_SIG_LENGTH_BYTES
135
+ * in @stacks/transactions/src/constants.ts
136
+ *
137
+ * @param {string} message - message to verify the signature
138
+ * @param {string} signature - signature to verify
139
+ * @param {string} publicKey - public key as hex string used to verify the signature
140
+ * @returns {boolean} - verification result
141
+ */
142
+ export declare function verifySignature(message: string, signature: string, publicKey: string): boolean;
143
+ /**
144
+ * Process address into address and memo id
145
+ *
146
+ * @param {string} address the address to process
147
+ * @returns {Object} object containing address and memo id
148
+ */
149
+ export declare function getAddressDetails(address: string): AddressDetails;
150
+ /**
151
+ * Validate and return address with appended memo id
152
+ *
153
+ * @param {AddressDetails} addressDetails
154
+ * @returns {string} address with memo id
155
+ */
156
+ export declare function normalizeAddress({ address, memoId }: AddressDetails): string;
157
+ /**
158
+ * Return boolean indicating whether input is a valid address with memo id
159
+ *
160
+ * @param {string} address address in the form <address>?memoId=<memoId>
161
+ * @returns {boolean} true is input is a valid address
162
+ */
163
+ export declare function isValidAddressWithPaymentId(address: string): boolean;
164
+ /**
165
+ * Return string representation of clarity value input
166
+ *
167
+ * @param {ClarityValue} cv clarity value function argument
168
+ * @returns {String} stringified clarity value
169
+ */
170
+ export declare function stringifyCv(cv: ClarityValue): any;
171
+ /**
172
+ * Parse functionArgs into send params for send-many-memo contract calls
173
+ *
174
+ * @param {ClarityValue[]} args functionArgs from a contract call payload
175
+ * @returns {SendParams[]} An array of sendParams
176
+ */
177
+ export declare function functionArgsToSendParams(args: ClarityValue[]): SendParams[];
178
+ /**
179
+ * Gets the version of an address
180
+ *
181
+ * @param {String} address the address with or without the memoId
182
+ * @returns {AddressVersion} A number that represent the Address Version
183
+ */
184
+ export declare function getAddressVersion(address: string): AddressVersion;
185
+ /**
186
+ * Returns a STX pub key from an xpub
187
+ *
188
+ * @param {String} xpub an xpub
189
+ * @returns {String} a compressed STX pub key
190
+ */
191
+ export declare function xpubToSTXPubkey(xpub: string, compressed?: boolean): string;
192
+ /**
193
+ * Returns the base address portion of an address
194
+ *
195
+ * @param {String} address - an address
196
+ * @returns {String} - the base address
197
+ */
198
+ export declare function getBaseAddress(address: string): string;
199
+ /**
200
+ * Compares an address to the base address to check if matchs.
201
+ *
202
+ * @param {String} address - an address
203
+ * @param {String} baseAddress - a base address
204
+ * @returns {boolean}
205
+ */
206
+ export declare function isSameBaseAddress(address: string, baseAddress: string): boolean;
207
+ //# sourceMapping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