1
1
A Libra js client library with crypto verifications, for NodeJS and browsers.
2
2
3
+ Compatible with libra testnet updated on 4/8/2020.
4
+
3
5
# Usage
4
6
5
7
In order to work with browsers, ` gopherjs-libra ` uses gRPC-Web which is not directly compatible with gRPC. A proxy is needed to forward gRPC-Web requests to gRPC backends. You can setup an Envoy proxy (https://grpc.io/docs/tutorials/basic/web/ ), or use my demo proxy shown in the examples.
@@ -62,7 +64,10 @@ const { libra } = require("gopherjs-libra");
62
64
63
65
keyPair = sign .keyPair ();
64
66
address = libra .pubkeyToAddress (keyPair .publicKey );
65
- // address is a libra account address (Uint8Array, 32-byte)
67
+ authKey = libra .pubkeyToAuthKey (keyPair .publicKey );
68
+ // address is a libra account address (Uint8Array, 16-byte)
69
+ // authKey is the full auth key (Uint8Array, 32-byte)
70
+ // Use authkey[0:16] if you need authKeyPrefix
66
71
// keyPair.secretKey is the corresponding private key (Uint8Array, 64-byte)
67
72
```
68
73
@@ -120,6 +125,10 @@ Arguments:
120
125
121
126
Returns a ` Uint8Array ` : the raw path to the Libra account resource, which is ` 0x01+hash(0x0.LibraAccount.T) ` .
122
127
128
+ ### ` .balanceResourcePath() `
129
+
130
+ Returns a ` Uint8Array ` : the raw path to the Libra balance resource, which is ` 0x01+hash(0x0.LibraAccount.Balance) ` .
131
+
123
132
### ` .accountSentEventPath() `
124
133
125
134
Returns a ` Uint8Array ` : the raw path to Libra coin sent events, which is ` 0x01+hash(0x0.LibraAccount.T)/sent_events_count/ ` .
@@ -133,7 +142,14 @@ Returns a `Uint8Array`: the raw path to Libra coin received events, which is `0x
133
142
Arguments:
134
143
- publicKey (Uint8Array): 32-byte ed25519 public key.
135
144
136
- Returns SHA3 hash of input public key, which is used as Libra account address.
145
+ Returns last 16 bytes of SHA3 hash of input public key, which is used as Libra account address.
146
+
147
+ ### ` .pubkeyToAuthKey(publicKey) `
148
+
149
+ Arguments:
150
+ - publicKey (Uint8Array): 32-byte ed25519 public key.
151
+
152
+ Returns the full SHA3 hash of input public key, which is used as initial Libra account auth key.
137
153
138
154
## Object: ` Client `
139
155
@@ -176,6 +192,7 @@ Arguments:
176
192
- ` p2pTxn ` (Object): a p2p transaction object, with following keys
177
193
- ` senderAddr ` (Uint8Array): sender address
178
194
- ` recvAddr ` (Uint8Array): receiver address
195
+ - ` recvAuthKeyPrefix ` (Uint8Array): receiver auth key prefix (first 16 bytes of auth key)
179
196
- ` senderPrivateKey ` (Uint8Array): sender ed25519 secret key (64 bytes)
180
197
- ` senderSeq ` (integer): current sender account sequence number
181
198
- ` amountMicro ` (integer): amount to transfer in micro libra
@@ -300,20 +317,7 @@ It has a list of getters (with return type), whose names are self-descriptive:
300
317
- ` .getLedgerInfo() ` (` provenLedgerInfo ` )
301
318
- ` .getAddress() ` (Uint8Array)
302
319
- ` .getResource(path) ` (Uint8Array): Returns a binary resource content on the given access path. Use ` resourcePath() ` to build a path.
303
- - ` .getLibraAccountResource() ` (` provenAccountResource ` ): Returns the Libra account resource.
304
-
305
- ## Object: ` provenAccountResource `
306
-
307
- Represents the libra account resource (0x0.LibraAccount.T) of an account, proven to be at a certain version.
308
-
309
- It has a list of getters (with return type), whose names are self-descriptive:
310
- - ` .getLedgerInfo() ` (` provenLedgerInfo ` )
311
- - ` .getAddress() ` (Uint8Array)
312
- - ` .getBalance() ` (integer)
313
- - ` .getSequenceNumber() ` (integer)
314
- - ` .getSentEvents() ` (object)
315
- - ` .getReceivedEvents() ` (object)
316
- - ` .getDelegatedWithdrawalCapability() ` (bool)
320
+ - ` .getLibraResources() ` (object): Returns the Libra account resources, i.e. ` accountResource ` and ` balanceResource ` .
317
321
318
322
## Object: ` provenTransaction `
319
323
0 commit comments