@exodus/asset-types 0.0.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.
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@exodus/asset-types",
3
+ "version": "0.0.0",
4
+ "description": "Typings for Assets",
5
+ "author": "Exodus Movement, Inc.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/ExodusMovement/assets.git"
9
+ },
10
+ "homepage": "https://github.com/ExodusMovement/assets/tree/master/shield/asset-types",
11
+ "license": "UNLICENSED",
12
+ "type": "module",
13
+ "main": "src/index.d.ts",
14
+ "files": [
15
+ "src",
16
+ "README.md",
17
+ "CHANGELOG.md"
18
+ ],
19
+ "dependencies": {
20
+ "@exodus/currency": "^6.0.1",
21
+ "@exodus/key-identifier": "^1.3.0",
22
+ "@exodus/models": "^12.2.0"
23
+ },
24
+ "scripts": {
25
+ "lint": "run -T eslint .",
26
+ "lint:fix": "yarn lint --fix"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/ExodusMovement/assets/issues?q=is%3Aissue+is%3Aopen+label%3Aasset-types"
30
+ },
31
+ "gitHead": "0ff44cf074103d3aee53b875d7026fae26bde5fc"
32
+ }
@@ -0,0 +1,40 @@
1
+ import type { UnitType } from '@exodus/currency'
2
+
3
+ export type GradientCoords = {
4
+ x1: string
5
+ y1: string
6
+ x2: string
7
+ y2: string
8
+ }
9
+
10
+ export type Info = {
11
+ description?: string
12
+ reddit?: string
13
+ twitter?: string
14
+ website?: string
15
+ telegram?: string
16
+ }
17
+
18
+ export type AssetMeta = {
19
+ assetType: string
20
+ baseAssetName: string
21
+ blockExplorer: {
22
+ txUrl: (txId: string) => Promise<string>
23
+ addressUrl: (address: string) => Promise<string>
24
+ }
25
+ chainBadgeColors: string[]
26
+ currency: UnitType
27
+ displayNetworkName: string
28
+ displayNetworkTicker: string
29
+ displayTicker: string
30
+ gradientColors: string[]
31
+ gradientCoords: GradientCoords
32
+ tokenAssetType?: string
33
+ info?: Info
34
+ primaryColor: string
35
+ displayName: string
36
+ name: string
37
+ ticker: string
38
+ decimals?: number
39
+ mintAddress?: string
40
+ }
package/src/asset.d.ts ADDED
@@ -0,0 +1,167 @@
1
+ /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
+
3
+ import type NumberUnit from '@exodus/currency'
4
+ import type KeyIdentifier from '@exodus/key-identifier'
5
+ import type { AccountState, Tx, TxSet, WalletAccount } from '@exodus/models'
6
+
7
+ import type { AssetMeta } from './asset-meta.js'
8
+ import type { CreateFeeMonitorApi } from './fee-monitor.js'
9
+ import type { HistoryMonitor } from './history-monitor.js'
10
+ import type { Logger } from './logger.js'
11
+ import type { MoveFunds } from './move-funds.js'
12
+ import type { Signer } from './signer.js'
13
+
14
+ export type CreateHistoryMonitorApi = (args: {
15
+ asset: BaseAsset
16
+ runner: () => void
17
+ yieldToUI: () => void
18
+ logger: Logger
19
+ }) => HistoryMonitor
20
+
21
+ export type ApiFeatures = {
22
+ accountState?: boolean
23
+ customTokens?: boolean
24
+ feeMonitor?: boolean
25
+ feesApi?: boolean
26
+ isMaxFeeAsset?: boolean
27
+ isTestnet?: boolean
28
+ nfts?: boolean
29
+ noHistory?: boolean
30
+ signWithSigner?: boolean
31
+ signMessageWithSigner?: boolean
32
+ }
33
+
34
+ export type BalanceFieldName =
35
+ | 'total'
36
+ | 'balance'
37
+ | 'spendable'
38
+ | 'spendableBalance'
39
+ | 'unconfirmedSent'
40
+ | 'unconfirmedReceived'
41
+ | 'unspendable'
42
+ | 'walletReserve'
43
+ | 'networkReserve'
44
+ | 'staking'
45
+ | 'staked'
46
+ | 'stakable'
47
+ | 'unstaking'
48
+ | 'unstaked'
49
+ | 'rewards'
50
+ | 'frozen'
51
+
52
+ export type Balances = Record<BalanceFieldName, NumberUnit>
53
+
54
+ export type CommonAssetApi = {
55
+ features: ApiFeatures
56
+ getActivityTxs?: (params: { txs: Tx[] }) => Tx[]
57
+ getBalances: (args: {
58
+ asset: AbstractAsset
59
+ accountState: AccountState
60
+ txLog: TxSet
61
+ }) => Balances
62
+ getTxLogFilter?: (tx: Tx) => boolean
63
+ hasFeature: (feature: keyof ApiFeatures) => boolean // @deprecated use api.features instead
64
+ }
65
+
66
+ /// Not all assets txsend can handle all params. This needs to be improved!
67
+ type TxSendParams = any
68
+ // for future reference
69
+ // type TxSendParams = {
70
+ // address: string
71
+ // amount?: NumberUnit
72
+ // asset: TokenAsset | BaseAsset
73
+ // bumpTxId?: string
74
+ // customFee?: NumberUnit
75
+ // feeAmount?: NumberUnit
76
+ // feeOpts?: { [key: string]: any } // eth, move out!
77
+ // isExchange?: boolean
78
+ // isSendAll?: boolean
79
+ // nft?: { nftId: string; [key: string]: any }
80
+ // options: { [key: string]: any }
81
+ // shouldLog?: boolean
82
+ // walletAccount: string
83
+ // [key: string]: any
84
+ // }
85
+
86
+ export type AssetApi = CommonAssetApi & {
87
+ addressHasHistory?: (address: string) => Promise<boolean>
88
+ broadcastTx: (rawTx: Buffer) => Promise<any>
89
+ createAccountState?: () => typeof AccountState
90
+ createFeeMonitor: CreateFeeMonitorApi
91
+ createHistoryMonitor: CreateHistoryMonitorApi
92
+ defaultAddressPath: string
93
+ getBalanceForAddress: (address: string) => NumberUnit
94
+ getConfirmationsNumber: () => number
95
+ getDefaultAddressPath?: (args: {
96
+ walletAccount: WalletAccount
97
+ compatibilityMode?: string
98
+ }) => string
99
+ getFeeData: () => any
100
+ getKeyIdentifier(params: {
101
+ purpose: number
102
+ accountIndex: number
103
+ chainIndex?: number
104
+ addressIndex?: number
105
+ compatibilityMode?: string
106
+ }): KeyIdentifier
107
+ getSupportedPurposes?: (params?: { compatibilityMode?: string; isMultisig?: boolean }) => number[]
108
+ moveFunds?: MoveFunds
109
+ signHardware?: (params: {
110
+ unsignedTx: any
111
+ hardwareDevice: any
112
+ accountIndex: number
113
+ }) => Promise<any>
114
+ signMessage?(params: { message: any; signer: Signer }): Promise<any>
115
+ signTx(params: { unsignedTx: any; signer: Signer }): Promise<any>
116
+ sendTx(params: TxSendParams): Promise<{ txId: string }>
117
+ validateAssetId?: (assetId: string) => boolean
118
+ }
119
+
120
+ export type TokenAssetApi = {
121
+ getBalances: (params: {
122
+ asset: AbstractAsset
123
+ accountState: AccountState
124
+ txLog: TxSet
125
+ }) => Balances
126
+ }
127
+
128
+ export type AbstractAsset = AssetMeta & {
129
+ baseAsset: BaseAsset
130
+ feeAsset: AbstractAsset
131
+ isBuiltIn?: boolean
132
+ isCustomToken?: boolean
133
+ isCombined?: boolean
134
+ lifecycleStatus?: string
135
+ keys: {
136
+ encodePrivate: (key: Buffer) => string
137
+ encodePublic: (key: Buffer, options?: { purpose?: number }) => string
138
+ }
139
+ address: {
140
+ validate: (address: string) => boolean
141
+ resolvePurpose?: (address: string) => Promise<number>
142
+ }
143
+ }
144
+
145
+ export type CombinedAsset<A extends BaseAsset | TokenAsset = BaseAsset | TokenAsset> = AssetMeta & {
146
+ isCombined: true
147
+ combinedAssets: A[]
148
+ combinedAssetNames: A['name'][]
149
+ }
150
+
151
+ export type BaseAsset = AbstractAsset & {
152
+ api: AssetApi
153
+ }
154
+
155
+ export type TokenAsset = AbstractAsset & {
156
+ assetId?: string
157
+ api: CommonAssetApi
158
+ }
159
+
160
+ export type AssetPlugin<A = BaseAsset, C = unknown> = {
161
+ createAsset: (params: {
162
+ assetClientInterface: any
163
+ // extract interface
164
+ config: C
165
+ overrideCallback?: ({ asset: A }) => A
166
+ }) => A
167
+ }
@@ -0,0 +1,14 @@
1
+ import type NumberUnit from '@exodus/currency'
2
+
3
+ export type FeeMonitor = {
4
+ start: () => Promise<void>
5
+ stop: () => Promise<void>
6
+ tick: () => Promise<void>
7
+ }
8
+
9
+ export type CreateFeeMonitorApi = (params: {
10
+ updateFee: (
11
+ assetName: string,
12
+ feeDataToUpdate: Record<string, number | string | NumberUnit>
13
+ ) => Promise<void>
14
+ }) => FeeMonitor
@@ -0,0 +1,15 @@
1
+ /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
+
3
+ export type HookEvent = ['start', 'stop', 'update', 'tick', 'tick-multiple-wallet-accounts']
4
+
5
+ export type HistoryMonitor = {
6
+ start: (params?: any) => Promise<void>
7
+ stop: () => Promise<void>
8
+ addHook: (event: HookEvent, callback: (params: any) => Promise<void>) => void
9
+ update: (args?: {
10
+ walletAccount: string
11
+ refresh?: boolean
12
+ highPriority?: boolean
13
+ assetName?: string
14
+ }) => Promise<void>
15
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export type {
2
+ //
3
+ AbstractAsset,
4
+ AssetPlugin,
5
+ BaseAsset,
6
+ CombinedAsset,
7
+ TokenAsset,
8
+ } from './asset.js'
@@ -0,0 +1,8 @@
1
+ // compied from hydra, share!
2
+ export type Args = [unknown, ...unknown[]]
3
+
4
+ export type LogLevel = 'trace' | 'debug' | 'log' | 'info' | 'warn' | 'error'
5
+
6
+ export type LogFn = (...args: Args) => void
7
+
8
+ export type Logger = Record<LogLevel, LogFn>
@@ -0,0 +1,35 @@
1
+ import type NumberUnit from '@exodus/currency'
2
+
3
+ export type MoveFunds = {
4
+ prepareSendFundsTx: (params: {
5
+ assetName: string
6
+ walletAccount: string
7
+ input: string
8
+ toAddress: string
9
+ MoveFundsError: typeof Error
10
+ }) => Promise<{
11
+ amount: NumberUnit
12
+ fee: NumberUnit
13
+ fromAddress: string
14
+ privateKey: string
15
+ toAddress: string
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ unsignedTx: any
18
+ }>
19
+ sendFunds: (params: {
20
+ amount: NumberUnit
21
+ assetName: string
22
+ fee: NumberUnit
23
+ fromAddress: string
24
+ privateKey: string
25
+ toAddress: string
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ unsignedTx: any
28
+ }) => Promise<{
29
+ amount: NumberUnit
30
+ fee: NumberUnit
31
+ fromAddress: string
32
+ toAddress: string
33
+ txId: string
34
+ }>
35
+ }
@@ -0,0 +1,46 @@
1
+ import type KeyIdentifier from '@exodus/key-identifier'
2
+
3
+ // move to hydra!
4
+
5
+ export type SignatureEncoding = 'raw' | 'der' | 'sig' | 'sig|rec' | 'rec|sig' | 'sig,rec'
6
+
7
+ type BaseSignParams = {
8
+ keyId?: KeyIdentifier
9
+ }
10
+
11
+ export enum SignatureType {
12
+ Ed25519 = 'ed25519',
13
+ Ecdsa = 'ecdsa',
14
+ }
15
+
16
+ export type EcdsaSignParams<Enc extends SignatureEncoding> = {
17
+ signatureType: SignatureType.Ecdsa
18
+ data: Buffer
19
+ ecOptions?: { canoncial?: boolean }
20
+ extraEntropy?: Buffer
21
+ enc: Enc
22
+ } & BaseSignParams
23
+
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ export type EncodedEcdsaSignature<Enc extends SignatureEncoding> = Enc extends 'der' ? Buffer : any
26
+
27
+ export type Ed25519SignParams = {
28
+ signatureType: SignatureType.Ed25519
29
+ data: Buffer
30
+ } & BaseSignParams
31
+
32
+ export type SignParams<Enc extends SignatureEncoding> = EcdsaSignParams<Enc> | Ed25519SignParams
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ export type SignReturnValue<T extends SignParams<any>> =
35
+ T extends EcdsaSignParams<infer Enc> ? EncodedEcdsaSignature<Enc> : Buffer
36
+
37
+ export type GetPublicKeyParams = {
38
+ keyId?: KeyIdentifier
39
+ }
40
+
41
+ export interface Signer {
42
+ getPublicKey(params?: GetPublicKeyParams): Promise<Buffer>
43
+ sign<Enc extends SignatureEncoding>(
44
+ signParams: SignParams<Enc>
45
+ ): Promise<SignReturnValue<typeof signParams>>
46
+ }