This repository has been archived by the owner on Feb 25, 2018. It is now read-only.
/
trustbase.d.ts
158 lines (131 loc) · 3.93 KB
/
trustbase.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import * as web3 from './web3.d'
declare interface AsyncProvider {
sendAsync(payload: web3.JsonRPCRequest, callback: (e: Error, val: web3.JsonRPCResponse) => void): void
}
declare interface InitOptions {
provider: AsyncProvider | string
defaultAccount?: string
}
declare interface ContractOptions {
networks?: {
[networkId: number]: {
address: string
}
}
address?: string
networkId?: number
}
declare interface ContractMethodOptions {
from?: string
gas?: string | number
gasPrice?: string | number
}
declare interface Identity {
publicKey: string
blockNumber: number
0: string
1: number
}
declare interface GetMessagesOption {
fromBlock?: web3.BlockType
toBlock?: web3.BlockType
}
declare interface Message {
message: string
timestamp: string
}
declare interface QueriedMessages {
lastBlock: number
messages: Array<Message>
}
declare interface GetBroadcastMessagesOption {
filter?: any
fromBlock?: web3.BlockType
toBlock?: web3.BlockType
}
declare interface BroadcastMessage {
message: string
userAddress: string
timestamp: string
}
declare interface QueriedBroadcastMessages {
lastBlock: number
broadcastMessages: Array<BroadcastMessage>
}
declare interface GetBindEventsOption {
filter?: {
[indexedParam: string]: any
}
fromBlock?: web3.BlockType
toBlock?: web3.BlockType
}
declare interface BindEvent {
userAddress: string,
signedBoundSocials: string,
}
declare interface QueriedBindEvents {
lastBlock: number
bindEvents: Array<BindEvent>
}
declare enum ErrorCode {
UNKNOWN = 0,
UNINITIALIZED_WEB3 = 100,
INITIALIZED_ALREADY = 101,
PROVIDER_NOT_PROVIDED = 102,
INVALID_ACCOUNT_ADDRESS = 200,
ACCOUNT_NOT_EXIST = 201,
FOUND_NO_ACCOUNT = 202,
NETWORK_MISMATCH = 300,
INVALID_CONTRACT_ADDRESS = 301
}
declare module trustbase {
function getWeb3(): web3.Web3
function sha3(str: string): string
function asciiToHex(str: string): string
function hexToAscii(hex: string): string
function initialize(options: InitOptions): Promise<void>
class Identities {
web3: web3.Web3
contract: web3.Contract
constructor(options?: ContractOptions)
register(identityPublicKey: string, options?: ContractMethodOptions): web3.PromiEvent<web3.TransactionReceipt>
getIdentity(userAddress: string, options?: ContractMethodOptions): Promise<Identity>
}
class Messages {
web3: web3.Web3
contract: web3.Contract
constructor(options?: ContractOptions)
publish(message: string, options?: ContractMethodOptions): web3.PromiEvent<web3.TransactionReceipt>
getMessages(options: GetMessagesOption): Promise<QueriedMessages>
}
class BroadcastMessages {
web3: web3.Web3
contract: web3.Contract
constructor(options?: ContractOptions)
publish(signedMessage: string, userAddress: string, options?: ContractMethodOptions): web3.PromiEvent<web3.TransactionReceipt>
getBroadcastMessages(options?: GetBroadcastMessagesOption): Promise<QueriedBroadcastMessages>
}
class BoundSocials {
web3: web3.Web3
contract: web3.Contract
constructor(options?: ContractOptions)
bind(userAddress: string, signedBoundSocials: string, options?: ContractMethodOptions): web3.PromiEvent<web3.TransactionReceipt>
getBindEvents(options?: GetBindEventsOption): Promise<QueriedBindEvents>
}
class TrustbaseError extends Error {
static readonly CODE: {
UNKNOWN: ErrorCode.UNKNOWN
UNINITIALIZED_WEB3: ErrorCode.UNINITIALIZED_WEB3
INITIALIZED_ALREADY: ErrorCode.INITIALIZED_ALREADY
PROVIDER_NOT_PROVIDED: ErrorCode.PROVIDER_NOT_PROVIDED
INVALID_ACCOUNT_ADDRESS: ErrorCode.INVALID_ACCOUNT_ADDRESS
ACCOUNT_NOT_EXIST: ErrorCode.ACCOUNT_NOT_EXIST
FOUND_NO_ACCOUNT: ErrorCode.FOUND_NO_ACCOUNT
NETWORK_MISMATCH: ErrorCode.NETWORK_MISMATCH
INVALID_CONTRACT_ADDRESS: ErrorCode.INVALID_CONTRACT_ADDRESS
}
code: ErrorCode
constructor(message: string, code?: ErrorCode)
}
}
export = trustbase