1
- import * as LIT from 'types/generated/lit-sessions_pb' ;
1
+ import * as ACCOUNT from 'types/generated/lit-accounts_pb' ;
2
+ import * as SESSION from 'types/generated/lit-sessions_pb' ;
3
+ import { Accounts } from 'types/generated/lit-accounts_pb_service' ;
2
4
import { Sessions } from 'types/generated/lit-sessions_pb_service' ;
3
5
import { b64 } from 'util/strings' ;
6
+ import { MAX_DATE } from 'util/constants' ;
4
7
import BaseApi from './base' ;
5
8
import GrpcClient from './grpc' ;
6
9
@@ -16,24 +19,46 @@ class LitApi extends BaseApi<LitEvents> {
16
19
this . _grpc = grpc ;
17
20
}
18
21
22
+ /**
23
+ * call the Lit `CreateAccount` RPC and return the response
24
+ */
25
+ async createAccount (
26
+ accountBalance : number ,
27
+ expirationDate : Date ,
28
+ ) : Promise < ACCOUNT . CreateAccountResponse . AsObject > {
29
+ const req = new ACCOUNT . CreateAccountRequest ( ) ;
30
+ req . setAccountBalance ( accountBalance . toString ( ) ) ;
31
+
32
+ if ( expirationDate === MAX_DATE ) {
33
+ req . setExpirationDate ( '0' ) ;
34
+ } else {
35
+ req . setExpirationDate ( Math . floor ( expirationDate . getTime ( ) / 1000 ) . toString ( ) ) ;
36
+ }
37
+
38
+ const res = await this . _grpc . request ( Accounts . CreateAccount , req , this . _meta ) ;
39
+ return res . toObject ( ) ;
40
+ }
41
+
19
42
/**
20
43
* call the Lit `AddSession` RPC and return the response
21
44
*/
22
45
async addSession (
23
46
label : string ,
24
- sessionType : LIT . SessionTypeMap [ keyof LIT . SessionTypeMap ] ,
47
+ sessionType : SESSION . SessionTypeMap [ keyof SESSION . SessionTypeMap ] ,
25
48
expiry : Date ,
26
49
mailboxServerAddr : string ,
27
50
devServer : boolean ,
28
- macaroonCustomPermissions : Array < LIT . MacaroonPermission > ,
29
- ) : Promise < LIT . AddSessionResponse . AsObject > {
30
- const req = new LIT . AddSessionRequest ( ) ;
51
+ macaroonCustomPermissions : Array < SESSION . MacaroonPermission > ,
52
+ accountId : string ,
53
+ ) : Promise < SESSION . AddSessionResponse . AsObject > {
54
+ const req = new SESSION . AddSessionRequest ( ) ;
31
55
req . setLabel ( label ) ;
32
56
req . setSessionType ( sessionType ) ;
33
57
req . setExpiryTimestampSeconds ( Math . floor ( expiry . getTime ( ) / 1000 ) . toString ( ) ) ;
34
58
req . setMailboxServerAddr ( mailboxServerAddr ) ;
35
59
req . setDevServer ( devServer ) ;
36
60
req . setMacaroonCustomPermissionsList ( macaroonCustomPermissions ) ;
61
+ req . setAccountId ( accountId ) ;
37
62
38
63
const res = await this . _grpc . request ( Sessions . AddSession , req , this . _meta ) ;
39
64
return res . toObject ( ) ;
@@ -42,8 +67,8 @@ class LitApi extends BaseApi<LitEvents> {
42
67
/**
43
68
* call the Lit `ListSessions` RPC and return the response
44
69
*/
45
- async listSessions ( ) : Promise < LIT . ListSessionsResponse . AsObject > {
46
- const req = new LIT . ListSessionsRequest ( ) ;
70
+ async listSessions ( ) : Promise < SESSION . ListSessionsResponse . AsObject > {
71
+ const req = new SESSION . ListSessionsRequest ( ) ;
47
72
const res = await this . _grpc . request ( Sessions . ListSessions , req , this . _meta ) ;
48
73
return res . toObject ( ) ;
49
74
}
@@ -53,8 +78,8 @@ class LitApi extends BaseApi<LitEvents> {
53
78
*/
54
79
async revokeSession (
55
80
localPublicKey : string ,
56
- ) : Promise < LIT . RevokeSessionResponse . AsObject > {
57
- const req = new LIT . RevokeSessionRequest ( ) ;
81
+ ) : Promise < SESSION . RevokeSessionResponse . AsObject > {
82
+ const req = new SESSION . RevokeSessionRequest ( ) ;
58
83
req . setLocalPublicKey ( b64 ( localPublicKey ) ) ;
59
84
const res = await this . _grpc . request ( Sessions . RevokeSession , req , this . _meta ) ;
60
85
return res . toObject ( ) ;
0 commit comments