1
1
import jsonrpc from "/lib/api/jsonrpc" ;
2
+ import { ChainId } from "/lib/crosschain/chains" ;
3
+ import KPassLite from "/lib/ethereum/KPassLite" ;
2
4
import evm from "/lib/ethereum/evm" ;
3
5
4
- /**
5
- * @const {string}
6
- * @noinline
7
- */
8
- const TCKT_ADDR = "0xcCc0a9b023177549fcf26c947edb5bfD9B230cCc" ;
9
-
10
6
/**
11
7
* @constructor
12
8
*
13
- * @param {!Object<string , string> } nodeUrls
9
+ * @param {!Object<ChainId , string> } nodeUrls
14
10
*/
15
- function TCKT ( nodeUrls ) {
16
- /** @const {!Object<string , string>} */
11
+ function KPass ( nodeUrls ) {
12
+ /** @const {!Object<ChainId , string>} */
17
13
this . nodeUrls = nodeUrls ;
18
14
}
19
15
16
+ KPass . prototype . ADDRS = KPassLite . KPASS_ADDRS ;
17
+
20
18
/**
21
19
* Note exposure reports are filed only on Avalanche C-chain therefore this
22
20
* method does not take a `chainId`.
23
21
*
24
22
* @param {string } exposureReportID of length 64, hex encoded exposureReportID.
25
23
* @return {!Promise<number> } the timestamp of the last exposure report or zero.
26
24
*/
27
- TCKT . prototype . exposureReported = function ( exposureReportID ) {
28
- return jsonrpc . call ( this . nodeUrls [ "0xa86a" ] , 'eth_call' , [
25
+ KPass . prototype . exposureReported = function ( exposureReportID ) {
26
+ return jsonrpc . call ( this . nodeUrls [ ChainId . x144 ] , 'eth_call' , [
29
27
/** @type {!eth.Transaction } */ ( {
30
- to : TCKT_ADDR ,
28
+ to : KPassLite . getAddress ( ChainId . x144 ) ,
31
29
data : "0x72797221" + exposureReportID
32
30
} ) , "latest"
33
31
] ) . then ( ( /** @type {string } */ hexValue ) => parseInt ( hexValue . slice ( - 10 ) , 16 ) ) ;
@@ -40,12 +38,12 @@ TCKT.prototype.exposureReported = function (exposureReportID) {
40
38
* @param {string } address
41
39
* @return {!Promise<number> } the last revoke timestamp.
42
40
*/
43
- TCKT . prototype . lastRevokeTimestamp = function ( address ) {
41
+ KPass . prototype . lastRevokeTimestamp = function ( address ) {
44
42
/** @const {!Array<Promise<number>>} */
45
- const promises = Object . values ( this . nodeUrls ) . map ( ( nodeUrl ) =>
43
+ const promises = Object . entries ( this . nodeUrls ) . map ( ( [ /** ChainId */ chainId , nodeUrl ] ) =>
46
44
jsonrpc . call ( nodeUrl , 'eth_call' , [
47
45
/** @type {!eth.Transaction } */ ( {
48
- to : TCKT_ADDR ,
46
+ to : KPassLite . getAddress ( chainId ) ,
49
47
data : "0x6a0d104e" + evm . address ( address )
50
48
} ) , "latest"
51
49
] ) . then ( ( /** @type {string } */ hexValue ) => parseInt ( hexValue . slice ( - 10 ) , 16 ) )
@@ -56,19 +54,19 @@ TCKT.prototype.lastRevokeTimestamp = function (address) {
56
54
}
57
55
58
56
/**
59
- * @param {string } chainId
57
+ * @param {ChainId } chainId
60
58
* @param {string } address
61
59
* @return {!Promise<string> } the IPFS handle of the address, encoded as a
62
60
* length 66 hex string.
63
61
*/
64
- TCKT . prototype . handleOf = function ( chainId , address ) {
62
+ KPass . prototype . handleOf = function ( chainId , address ) {
65
63
return /** @type {!Promise<string> } */ ( jsonrpc . call ( this . nodeUrls [ chainId ] ,
66
64
'eth_call' , [
67
65
/** @type {!eth.Transaction } */ ( {
68
- to : TCKT_ADDR ,
66
+ to : KPassLite . getAddress ( chainId ) ,
69
67
data : "0xc50a1514" + evm . address ( address )
70
68
} ) , "latest"
71
69
] ) ) ;
72
70
}
73
71
74
- export { TCKT , TCKT_ADDR } ;
72
+ export { KPass } ;
0 commit comments