Package io.token.rpc

Class Client


  • public class Client
    extends java.lang.Object
    An authenticated RPC client that is used to talk to Token gateway. The class is a thin wrapper on top of gRPC generated client. Makes the API easier to use.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Client​(java.lang.String memberId, CryptoEngine crypto, GatewayProvider gateway)
      Creates a client instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected AuthenticationContext authenticationContext()  
      protected AuthenticationContext authenticationContext​(io.token.proto.common.security.SecurityProtos.Key.Level level)  
      io.reactivex.Observable<io.token.proto.common.security.SecurityProtos.Signature> authorizeRecovery​(io.token.proto.common.member.MemberProtos.MemberRecoveryOperation.Authorization authorization)
      Authorizes recovery as a trusted agent.
      io.reactivex.Observable<java.lang.Boolean> confirmFunds​(java.lang.String accountId, io.token.proto.common.money.MoneyProtos.Money amount)
      Confirm that the given account has sufficient funds to cover the charge.
      io.reactivex.Observable<io.token.proto.common.account.AccountProtos.Account> createAndLinkTestBankAccount​(io.token.proto.common.money.MoneyProtos.Money balance)
      Creates a test bank account and links it.
      io.reactivex.Completable deleteMember()
      Delete the member.
      boolean equals​(java.lang.Object obj)  
      io.reactivex.Observable<io.token.proto.common.account.AccountProtos.Account> getAccount​(java.lang.String accountId)
      Looks up a linked funding account.
      io.reactivex.Observable<java.util.List<io.token.proto.common.account.AccountProtos.Account>> getAccounts()
      Looks up all the linked funding accounts.
      io.reactivex.Observable<java.util.List<io.token.proto.common.alias.AliasProtos.Alias>> getAliases()
      Returns a list of aliases of the member.
      io.reactivex.Observable<io.token.proto.common.transaction.TransactionProtos.Balance> getBalance​(java.lang.String accountId, io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
      Look up account balance.
      io.reactivex.Observable<java.util.List<io.token.proto.common.transaction.TransactionProtos.Balance>> getBalances​(java.util.List<java.lang.String> accountIds, io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
      Look up balances for a list of accounts.
      io.reactivex.Observable<io.token.proto.common.bank.BankProtos.BankInfo> getBankInfo​(java.lang.String bankId)
      Returns linking information for the specified bank id.
      CryptoEngine getCryptoEngine()  
      io.reactivex.Observable<java.lang.String> getDefaultAgent()
      Gets the member id of the default recovery agent.
      io.reactivex.Observable<io.token.proto.common.member.MemberProtos.Member> getMember​(java.lang.String memberId)
      Looks up member information for the current user.
      protected java.lang.String getOnBehalfOf()  
      io.reactivex.Observable<io.token.proto.common.member.MemberProtos.Profile> getProfile​(java.lang.String memberId)
      Gets a member's public profile.
      io.reactivex.Observable<io.token.proto.common.blob.BlobProtos.Blob> getProfilePicture​(java.lang.String memberId, io.token.proto.common.member.MemberProtos.ProfilePictureSize size)
      Gets a member's public profile picture.
      io.reactivex.Observable<io.token.proto.common.transaction.TransactionProtos.StandingOrder> getStandingOrder​(java.lang.String accountId, java.lang.String standingOrderId, io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
      Look up an existing standing order and return the response.
      io.reactivex.Observable<io.token.proto.PagedList<io.token.proto.common.transaction.TransactionProtos.StandingOrder,​java.lang.String>> getStandingOrders​(java.lang.String accountId, java.lang.String offset, int limit, io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
      Look up standing orders and return response.
      io.reactivex.Observable<io.token.proto.common.transaction.TransactionProtos.Transaction> getTransaction​(java.lang.String accountId, java.lang.String transactionId, io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
      Look up an existing transaction and return the response.
      io.reactivex.Observable<io.token.proto.PagedList<io.token.proto.common.transaction.TransactionProtos.Transaction,​java.lang.String>> getTransactions​(java.lang.String accountId, java.lang.String offset, int limit, io.token.proto.common.security.SecurityProtos.Key.Level keyLevel, java.lang.String startDate, java.lang.String endDate)
      Lookup transactions and return response.
      int hashCode()  
      io.reactivex.Observable<java.util.List<io.token.proto.common.account.AccountProtos.Account>> linkAccounts​(io.token.proto.banklink.Banklink.OauthBankAuthorization authorization)
      Links a funding bank account to Token.
      protected io.token.proto.gateway.Gateway.Page.Builder pageBuilder​(java.lang.String offset, int limit)  
      io.reactivex.Observable<java.util.List<io.token.proto.common.transferinstructions.TransferInstructionsProtos.TransferDestination>> resolveTransferDestinations​(java.lang.String accountId)
      Resolves transfer destinations for the given account ID.
      io.reactivex.Observable<java.lang.String> retryVerification​(io.token.proto.common.alias.AliasProtos.Alias alias)
      Retry alias verification.
      io.token.proto.common.security.SecurityProtos.Signature signTokenPayload​(io.token.proto.common.token.TokenProtos.TokenPayload payload, io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
      Signs a token payload.
      protected java.lang.String tokenAction​(io.token.proto.common.token.TokenProtos.Token token, io.token.proto.common.token.TokenProtos.TokenSignature.Action action)  
      io.reactivex.Observable<io.token.proto.common.member.MemberProtos.Member> updateMember​(io.token.proto.common.member.MemberProtos.Member member, java.util.List<io.token.proto.common.member.MemberProtos.MemberOperation> operations)
      Updates member by applying the specified operations that don't contain addAliasOperation.
      io.reactivex.Observable<io.token.proto.common.member.MemberProtos.Member> updateMember​(io.token.proto.common.member.MemberProtos.Member member, java.util.List<io.token.proto.common.member.MemberProtos.MemberOperation> operations, java.util.List<io.token.proto.common.member.MemberProtos.MemberOperationMetadata> metadata)
      Updates member by applying the specified operations.
      io.reactivex.Completable useDefaultRecoveryRule()
      Set Token as the recovery agent.
      io.reactivex.Completable verifyAlias​(java.lang.String verificationId, java.lang.String code)
      Verifies a given alias.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • memberId

        protected final java.lang.String memberId
      • customerInitiated

        protected boolean customerInitiated
      • customerTrackingMetadata

        protected io.token.proto.common.security.SecurityProtos.CustomerTrackingMetadata customerTrackingMetadata
    • Constructor Detail

      • Client

        protected Client​(java.lang.String memberId,
                         CryptoEngine crypto,
                         GatewayProvider gateway)
        Creates a client instance.
        Parameters:
        memberId - member id
        crypto - the crypto engine used to sign for authentication, request payloads, etc
        gateway - gateway gRPC stub
    • Method Detail

      • getMember

        public io.reactivex.Observable<io.token.proto.common.member.MemberProtos.Member> getMember​(java.lang.String memberId)
        Looks up member information for the current user. The user is defined by the key used for authentication.
        Parameters:
        memberId - member id
        Returns:
        an observable of member
      • updateMember

        public io.reactivex.Observable<io.token.proto.common.member.MemberProtos.Member> updateMember​(io.token.proto.common.member.MemberProtos.Member member,
                                                                                                      java.util.List<io.token.proto.common.member.MemberProtos.MemberOperation> operations,
                                                                                                      java.util.List<io.token.proto.common.member.MemberProtos.MemberOperationMetadata> metadata)
        Updates member by applying the specified operations.
        Parameters:
        member - member to update
        operations - operations to apply
        metadata - metadata of operations
        Returns:
        an observable of updated member
      • updateMember

        public io.reactivex.Observable<io.token.proto.common.member.MemberProtos.Member> updateMember​(io.token.proto.common.member.MemberProtos.Member member,
                                                                                                      java.util.List<io.token.proto.common.member.MemberProtos.MemberOperation> operations)
        Updates member by applying the specified operations that don't contain addAliasOperation.
        Parameters:
        member - member to update
        operations - operations to apply
        Returns:
        an observable of updated member
      • useDefaultRecoveryRule

        public io.reactivex.Completable useDefaultRecoveryRule()
        Set Token as the recovery agent.
        Returns:
        a completable
      • getProfile

        public io.reactivex.Observable<io.token.proto.common.member.MemberProtos.Profile> getProfile​(java.lang.String memberId)
        Gets a member's public profile.
        Parameters:
        memberId - member Id whose profile we want
        Returns:
        their profile text
      • getProfilePicture

        public io.reactivex.Observable<io.token.proto.common.blob.BlobProtos.Blob> getProfilePicture​(java.lang.String memberId,
                                                                                                     io.token.proto.common.member.MemberProtos.ProfilePictureSize size)
        Gets a member's public profile picture.
        Parameters:
        memberId - member Id whose profile we want
        size - size category we want (small, medium, large, original)
        Returns:
        blob with picture; empty blob (no fields set) if has no picture
      • signTokenPayload

        public io.token.proto.common.security.SecurityProtos.Signature signTokenPayload​(io.token.proto.common.token.TokenProtos.TokenPayload payload,
                                                                                        io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
        Signs a token payload.
        Parameters:
        payload - token payload
        keyLevel - key level
        Returns:
        token payload signature
      • getAccount

        public io.reactivex.Observable<io.token.proto.common.account.AccountProtos.Account> getAccount​(java.lang.String accountId)
        Looks up a linked funding account.
        Parameters:
        accountId - account id
        Returns:
        account info
      • getAccounts

        public io.reactivex.Observable<java.util.List<io.token.proto.common.account.AccountProtos.Account>> getAccounts()
        Looks up all the linked funding accounts.
        Returns:
        list of linked accounts
      • getBalance

        public io.reactivex.Observable<io.token.proto.common.transaction.TransactionProtos.Balance> getBalance​(java.lang.String accountId,
                                                                                                               io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
        Look up account balance.
        Parameters:
        accountId - account id
        keyLevel - key level
        Returns:
        account balance
      • getBalances

        public io.reactivex.Observable<java.util.List<io.token.proto.common.transaction.TransactionProtos.Balance>> getBalances​(java.util.List<java.lang.String> accountIds,
                                                                                                                                io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
        Look up balances for a list of accounts.
        Parameters:
        accountIds - list of account ids
        keyLevel - key level
        Returns:
        list of balances
      • getTransaction

        public io.reactivex.Observable<io.token.proto.common.transaction.TransactionProtos.Transaction> getTransaction​(java.lang.String accountId,
                                                                                                                       java.lang.String transactionId,
                                                                                                                       io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
        Look up an existing transaction and return the response.
        Parameters:
        accountId - account id
        transactionId - transaction id
        keyLevel - key level
        Returns:
        transaction
      • getTransactions

        public io.reactivex.Observable<io.token.proto.PagedList<io.token.proto.common.transaction.TransactionProtos.Transaction,​java.lang.String>> getTransactions​(java.lang.String accountId,
                                                                                                                                                                         @Nullable
                                                                                                                                                                         java.lang.String offset,
                                                                                                                                                                         int limit,
                                                                                                                                                                         io.token.proto.common.security.SecurityProtos.Key.Level keyLevel,
                                                                                                                                                                         @Nullable
                                                                                                                                                                         java.lang.String startDate,
                                                                                                                                                                         @Nullable
                                                                                                                                                                         java.lang.String endDate)
        Lookup transactions and return response.
        Parameters:
        accountId - account id
        offset - offset
        limit - limit
        keyLevel - key level
        startDate - inclusive lower bound of transaction booking date
        endDate - inclusive upper bound of transaction booking date
        Returns:
        paged list of transactions
      • getStandingOrder

        public io.reactivex.Observable<io.token.proto.common.transaction.TransactionProtos.StandingOrder> getStandingOrder​(java.lang.String accountId,
                                                                                                                           java.lang.String standingOrderId,
                                                                                                                           io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
        Look up an existing standing order and return the response.
        Parameters:
        accountId - account ID
        standingOrderId - standing order ID
        keyLevel - key level
        Returns:
        transaction
      • getStandingOrders

        public io.reactivex.Observable<io.token.proto.PagedList<io.token.proto.common.transaction.TransactionProtos.StandingOrder,​java.lang.String>> getStandingOrders​(java.lang.String accountId,
                                                                                                                                                                             @Nullable
                                                                                                                                                                             java.lang.String offset,
                                                                                                                                                                             int limit,
                                                                                                                                                                             io.token.proto.common.security.SecurityProtos.Key.Level keyLevel)
        Look up standing orders and return response.
        Parameters:
        accountId - account ID
        offset - offset
        limit - limit
        keyLevel - key level
        Returns:
        paged list of standing orders
      • confirmFunds

        public io.reactivex.Observable<java.lang.Boolean> confirmFunds​(java.lang.String accountId,
                                                                       io.token.proto.common.money.MoneyProtos.Money amount)
        Confirm that the given account has sufficient funds to cover the charge.
        Parameters:
        accountId - account ID
        amount - charge amount
        Returns:
        true if the account has sufficient funds to cover the charge
      • getBankInfo

        public io.reactivex.Observable<io.token.proto.common.bank.BankProtos.BankInfo> getBankInfo​(java.lang.String bankId)
        Returns linking information for the specified bank id.
        Parameters:
        bankId - the bank id
        Returns:
        bank linking information
      • linkAccounts

        public io.reactivex.Observable<java.util.List<io.token.proto.common.account.AccountProtos.Account>> linkAccounts​(io.token.proto.banklink.Banklink.OauthBankAuthorization authorization)
                                                                                                                  throws BankAuthorizationRequiredException
        Links a funding bank account to Token.
        Parameters:
        authorization - OAuth authorization for linking
        Returns:
        list of linked accounts
        Throws:
        BankAuthorizationRequiredException - if bank authorization payload is required to link accounts
      • createAndLinkTestBankAccount

        public io.reactivex.Observable<io.token.proto.common.account.AccountProtos.Account> createAndLinkTestBankAccount​(io.token.proto.common.money.MoneyProtos.Money balance)
        Creates a test bank account and links it.
        Parameters:
        balance - account balance to set
        Returns:
        linked account
      • getAliases

        public io.reactivex.Observable<java.util.List<io.token.proto.common.alias.AliasProtos.Alias>> getAliases()
        Returns a list of aliases of the member.
        Returns:
        a list of aliases
      • retryVerification

        public io.reactivex.Observable<java.lang.String> retryVerification​(io.token.proto.common.alias.AliasProtos.Alias alias)
        Retry alias verification.
        Parameters:
        alias - the alias to be verified
        Returns:
        the verification id
      • authorizeRecovery

        public io.reactivex.Observable<io.token.proto.common.security.SecurityProtos.Signature> authorizeRecovery​(io.token.proto.common.member.MemberProtos.MemberRecoveryOperation.Authorization authorization)
        Authorizes recovery as a trusted agent.
        Parameters:
        authorization - the authorization
        Returns:
        the signature
      • getDefaultAgent

        public io.reactivex.Observable<java.lang.String> getDefaultAgent()
        Gets the member id of the default recovery agent.
        Returns:
        the member id
      • verifyAlias

        public io.reactivex.Completable verifyAlias​(java.lang.String verificationId,
                                                    java.lang.String code)
        Verifies a given alias.
        Parameters:
        verificationId - the verification id
        code - the code
        Returns:
        a completable
      • deleteMember

        public io.reactivex.Completable deleteMember()
        Delete the member.
        Returns:
        completable
      • resolveTransferDestinations

        public io.reactivex.Observable<java.util.List<io.token.proto.common.transferinstructions.TransferInstructionsProtos.TransferDestination>> resolveTransferDestinations​(java.lang.String accountId)
        Resolves transfer destinations for the given account ID.
        Parameters:
        accountId - account ID
        Returns:
        transfer destinations
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • authenticationContext

        protected AuthenticationContext authenticationContext​(io.token.proto.common.security.SecurityProtos.Key.Level level)
      • getOnBehalfOf

        protected java.lang.String getOnBehalfOf()
      • pageBuilder

        protected io.token.proto.gateway.Gateway.Page.Builder pageBuilder​(@Nullable
                                                                          java.lang.String offset,
                                                                          int limit)
      • tokenAction

        protected java.lang.String tokenAction​(io.token.proto.common.token.TokenProtos.Token token,
                                               io.token.proto.common.token.TokenProtos.TokenSignature.Action action)