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' ;
24import { Sessions } from 'types/generated/lit-sessions_pb_service' ;
35import { b64 } from 'util/strings' ;
6+ import { MAX_DATE } from 'util/constants' ;
47import BaseApi from './base' ;
58import GrpcClient from './grpc' ;
69
@@ -16,24 +19,46 @@ class LitApi extends BaseApi<LitEvents> {
1619 this . _grpc = grpc ;
1720 }
1821
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+
1942 /**
2043 * call the Lit `AddSession` RPC and return the response
2144 */
2245 async addSession (
2346 label : string ,
24- sessionType : LIT . SessionTypeMap [ keyof LIT . SessionTypeMap ] ,
47+ sessionType : SESSION . SessionTypeMap [ keyof SESSION . SessionTypeMap ] ,
2548 expiry : Date ,
2649 mailboxServerAddr : string ,
2750 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 ( ) ;
3155 req . setLabel ( label ) ;
3256 req . setSessionType ( sessionType ) ;
3357 req . setExpiryTimestampSeconds ( Math . floor ( expiry . getTime ( ) / 1000 ) . toString ( ) ) ;
3458 req . setMailboxServerAddr ( mailboxServerAddr ) ;
3559 req . setDevServer ( devServer ) ;
3660 req . setMacaroonCustomPermissionsList ( macaroonCustomPermissions ) ;
61+ req . setAccountId ( accountId ) ;
3762
3863 const res = await this . _grpc . request ( Sessions . AddSession , req , this . _meta ) ;
3964 return res . toObject ( ) ;
@@ -42,8 +67,8 @@ class LitApi extends BaseApi<LitEvents> {
4267 /**
4368 * call the Lit `ListSessions` RPC and return the response
4469 */
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 ( ) ;
4772 const res = await this . _grpc . request ( Sessions . ListSessions , req , this . _meta ) ;
4873 return res . toObject ( ) ;
4974 }
@@ -53,8 +78,8 @@ class LitApi extends BaseApi<LitEvents> {
5378 */
5479 async revokeSession (
5580 localPublicKey : string ,
56- ) : Promise < LIT . RevokeSessionResponse . AsObject > {
57- const req = new LIT . RevokeSessionRequest ( ) ;
81+ ) : Promise < SESSION . RevokeSessionResponse . AsObject > {
82+ const req = new SESSION . RevokeSessionRequest ( ) ;
5883 req . setLocalPublicKey ( b64 ( localPublicKey ) ) ;
5984 const res = await this . _grpc . request ( Sessions . RevokeSession , req , this . _meta ) ;
6085 return res . toObject ( ) ;
0 commit comments