UNPKG

@argent/x-sessions

Version:

Manage sessions for Argent X wallets

98 lines (96 loc) 4.63 kB
import { StarknetDomain, TypedData } from '@starknet-io/types-js'; import { Account, constants, Signature } from 'starknet'; import { AllowedMethod, BuildSessionAccountParams, CreateSessionParams, OffChainSession, Session, SessionKey, SessionMetadata, VerifySessionParams } from './session.types'; declare const sessionTypes: { StarknetDomain: { name: string; type: string; }[]; "Allowed Method": { name: string; type: string; }[]; Session: ({ name: string; type: string; contains?: undefined; } | { name: string; type: string; contains: string; })[]; }; export declare const ALLOWED_METHOD_HASH: string; declare const getSessionDomain: (chainId: constants.StarknetChainId) => StarknetDomain; declare const getSessionTypedData: (sessionRequest: OffChainSession, chainId: constants.StarknetChainId) => TypedData; declare const createOffchainSession: (allowed_methods: AllowedMethod[], expires_at: bigint, metadata: SessionMetadata, signerPublicKey: string) => OffChainSession; /** * Builds a session account using the provided session and session key. * @param {Object} params - The parameters for building the session account. * @param {Session} params.session - The session created by the dapp. * @param {SessionKey} params.sessionKey - The session key generated by the dapp. * @param {Provider} params.provider - The RPC provider. * @param {string} params.argentSessionServiceBaseUrl - The base URL of the Argent session service. * @param {boolean} params.useCacheAuthorisation - Whether to use cache authorisation. * @returns {Promise<Account>} A promise that resolves to the session account. */ declare const buildSessionAccount: ({ session, sessionKey, provider, argentSessionServiceBaseUrl, useCacheAuthorisation, }: BuildSessionAccountParams) => Promise<Account>; export interface CreateSessionRequestParams { chainId: constants.StarknetChainId; sessionParams: CreateSessionParams; } export interface SessionRequest { sessionTypedData: TypedData; offchainSession: OffChainSession; sessionKey: SessionKey; } /** * Creates a new session request. * * @param {Object} params - The parameters for creating the session request. * @param {constants.StarknetChainId} params.chainId - The chain ID for the session. * @param {CreateSessionParams} params.sessionParams - The parameters for the session. * @returns {Object} The session typed data and the offchain session object. * @throws {Error} If the sessionPublicKey is not provided. */ declare const createSessionRequest: ({ chainId, sessionParams, }: CreateSessionRequestParams) => SessionRequest; interface SignSessionMessageParams { address: string; authorisationSignature: Signature; sessionRequest: SessionRequest; chainId: constants.StarknetChainId; } /** * Creates a new session. * * @param {Object} params - The parameters for creating the session. * @param {string} params.address - The address of the user. * @param {Signature} params.authorisationSignature - The session signature. * @param {SessionRequest} params.sessionRequest - The session request. * @param {constants.StarknetChainId} params.chainId - The chain ID for the session. * @returns {Promise<Session>} A promise that resolves to the created session. * @throws {Error} If the sessionPublicKey is not provided. */ declare const createSession: ({ address, authorisationSignature, sessionRequest, chainId, }: SignSessionMessageParams) => Promise<Session>; /** * Verifies the integrity and authenticity of a session using the provided session key. * * @param {Object} params - The parameters for verifying the session. * @param {Session} params.session - The session to be verified. * @param {SessionKey} params.sessionKey - The session key used for verification. * @returns {boolean} Returns true if the session is valid and the signature matches, otherwise false. */ declare const verifySession: ({ session, sessionKey, }: VerifySessionParams) => boolean; /** * Converts a byte array to a hex string. * @param bytes The byte array to convert. * @returns The hex string. */ declare const bytesToHexString: (bytes: Uint8Array) => string; /** * Converts a hex string to a byte array. * @param hexString The hex string to convert. * @returns The byte array. */ declare const hexStringToBytes: (hexString: string) => Uint8Array; export { buildSessionAccount, createOffchainSession, createSession, createSessionRequest, getSessionDomain, getSessionTypedData, sessionTypes, verifySession, bytesToHexString, hexStringToBytes, };