diff --git a/README.md b/README.md index b8b8dc8..44dbff6 100644 --- a/README.md +++ b/README.md @@ -137,8 +137,8 @@ Executing transactions “from outside” allows an account to submit transactio This package expose a method in order to get the Call required to perform an execution from outside. ```typescript -// instantiate argent backend session service -const beService = new ArgentBackendSessionService( +// instantiate argent session service +const beService = new ArgentSessionService( dappKey.publicKey, accountSessionSignature ) diff --git a/src/__tests__/sessionBackendService.test.ts b/src/__tests__/sessionBackendService.test.ts index 1760d54..5623d51 100644 --- a/src/__tests__/sessionBackendService.test.ts +++ b/src/__tests__/sessionBackendService.test.ts @@ -7,8 +7,8 @@ import { OutsideExecution, getOutsideExecutionTypedData, } from "../outsideExecution" -import { ArgentBackendSessionService } from "../sessionBackendService" -import { BackendSignatureResponse } from "../sessionTypes" +import { ArgentSessionService } from "../argentSessionService" +import { ArgentServiceSignatureResponse } from "../sessionTypes" import { getSessionTypedData } from "../utils" export const restHandlers = [ @@ -34,10 +34,10 @@ export const restHandlers = [ const server = setupServer(...restHandlers) -describe("ArgentBackendSessionService", () => { +describe("ArgentSessionService", () => { const pubkey = "0x1234567890abcdef" const accountSessionSignature = ["123", "456"] - const service = new ArgentBackendSessionService( + const service = new ArgentSessionService( pubkey, accountSessionSignature, "http://localhost:3000", @@ -53,7 +53,7 @@ describe("ArgentBackendSessionService", () => { afterEach(() => server.resetHandlers()) describe("signTxAndSession", () => { - it("should sign the transactions and session and return a backend signature response", async () => { + it("should sign the transactions and session and return a argent service signature response", async () => { const cacheAuthorisation = false const sessionRequest = { @@ -79,20 +79,21 @@ describe("ArgentBackendSessionService", () => { StarknetChainId.SN_SEPOLIA, ) - const response: BackendSignatureResponse = await service.signTxAndSession( - [], - { - cairoVersion: "1", - chainId: StarknetChainId.SN_SEPOLIA, - maxFee: 1000n, - nonce: 1, - version: "0x2", - walletAddress: stark.randomAddress(), - }, - sessionTypedData, - [10n, 20n], - cacheAuthorisation, - ) + const response: ArgentServiceSignatureResponse = + await service.signTxAndSession( + [], + { + cairoVersion: "1", + chainId: StarknetChainId.SN_SEPOLIA, + maxFee: 1000n, + nonce: 1, + version: "0x2", + walletAddress: stark.randomAddress(), + }, + sessionTypedData, + [10n, 20n], + cacheAuthorisation, + ) expect(response).toEqual({ publicKey: "0x123", @@ -105,7 +106,7 @@ describe("ArgentBackendSessionService", () => { }) describe("signOutsideTxAndSession", () => { - it("should sign the outside session and return a backend signature response", async () => { + it("should sign the outside session and return an argent session signature response", async () => { const sessionTokenToSign = { expires_at: 1234567890, allowed_methods: [ @@ -155,14 +156,15 @@ describe("ArgentBackendSessionService", () => { const chainId: StarknetChainId = constants.StarknetChainId.SN_SEPOLIA - const response: BackendSignatureResponse = await service.signSessionEFO( - sessionTokenToSign, - accountAddress, - getOutsideExecutionTypedData(outsideExecution, chainId), - [123n, 456n], - false, - chainId, - ) + const response: ArgentServiceSignatureResponse = + await service.signSessionEFO( + sessionTokenToSign, + accountAddress, + getOutsideExecutionTypedData(outsideExecution, chainId), + [123n, 456n], + false, + chainId, + ) expect(response).toStrictEqual({ publicKey: "0x123", diff --git a/src/__tests__/sessionDappService.test.ts b/src/__tests__/sessionDappService.test.ts index 24396d7..b09f5aa 100644 --- a/src/__tests__/sessionDappService.test.ts +++ b/src/__tests__/sessionDappService.test.ts @@ -8,7 +8,7 @@ import { } from "starknet" import { StarknetChainId } from "starknet-types" import { beforeAll, describe, expect, it, vi } from "vitest" -import { ArgentBackendSessionService } from "../sessionBackendService" +import { ArgentSessionService } from "../argentSessionService" import { SessionDappService } from "../sessionDappService" import { outsideExecutionTypedDataFixture } from "./fixture" @@ -35,7 +35,7 @@ const sessionRequest = { const sessionAuthorizationSignature = ["signature1", "signature2"] describe("SessionDappService", () => { - let argentBackend: ArgentBackendSessionService + let argentSessionService: ArgentSessionService let chainId: StarknetChainId let privateDappKey: Uint8Array let publicDappKey: string @@ -45,12 +45,12 @@ describe("SessionDappService", () => { chainId = StarknetChainId.SN_GOERLI privateDappKey = ec.starkCurve.utils.randomPrivateKey() publicDappKey = ec.starkCurve.getStarkKey(privateDappKey) - argentBackend = new ArgentBackendSessionService( + argentSessionService = new ArgentSessionService( publicDappKey, sessionAuthorizationSignature, ) - vi.spyOn(argentBackend, "signTxAndSession").mockImplementation( + vi.spyOn(argentSessionService, "signTxAndSession").mockImplementation( async () => ({ publicKey: "0x123", r: 10n, @@ -58,7 +58,7 @@ describe("SessionDappService", () => { }), ) - sessionDappService = new SessionDappService(argentBackend, chainId, { + sessionDappService = new SessionDappService(argentSessionService, chainId, { privateKey: privateDappKey, publicKey: publicDappKey, }) @@ -79,7 +79,7 @@ describe("SessionDappService", () => { expect(account).toBeInstanceOf(Account) }) - it("should signTransaction calling argent backend", async () => { + it("should signTransaction calling argent session service", async () => { const invokationDetails: V2InvocationsSignerDetails = { cairoVersion: "1", chainId, @@ -100,8 +100,8 @@ describe("SessionDappService", () => { ) expect(signatureResult).toBeInstanceOf(Array) - expect(argentBackend.signTxAndSession).toHaveBeenCalled() - expect(argentBackend.signTxAndSession).toReturnWith({ + expect(argentSessionService.signTxAndSession).toHaveBeenCalled() + expect(argentSessionService.signTxAndSession).toReturnWith({ publicKey: "0x123", r: 10n, s: 10n, @@ -125,11 +125,13 @@ describe("SessionDappService", () => { }, ] - vi.spyOn(argentBackend, "signSessionEFO").mockImplementation(async () => ({ - publicKey: "0x123", - r: 10n, - s: 10n, - })) + vi.spyOn(argentSessionService, "signSessionEFO").mockImplementation( + async () => ({ + publicKey: "0x123", + r: 10n, + s: 10n, + }), + ) const outsideExecutionCall = await sessionDappService.getOutsideExecutionCall( @@ -167,11 +169,13 @@ describe("SessionDappService", () => { }, ] - vi.spyOn(argentBackend, "signSessionEFO").mockImplementation(async () => ({ - publicKey: "0x123", - r: 10n, - s: 10n, - })) + vi.spyOn(argentSessionService, "signSessionEFO").mockImplementation( + async () => ({ + publicKey: "0x123", + r: 10n, + s: 10n, + }), + ) const { signature, outsideExecutionTypedData } = await sessionDappService.getOutsideExecutionTypedData( diff --git a/src/sessionBackendService.ts b/src/argentSessionService.ts similarity index 89% rename from src/sessionBackendService.ts rename to src/argentSessionService.ts index 9ac5882..350e032 100644 --- a/src/sessionBackendService.ts +++ b/src/argentSessionService.ts @@ -12,21 +12,21 @@ import { } from "starknet" import { StarknetChainId, TypedData } from "starknet-types" -import { ARGENT_BACKEND_BASE_URL } from "./constants" +import { ARGENT_SESSION_SERVICE_BASE_URL } from "./constants" import { SignSessionError } from "./errors" import { - BackendSessionBody, - BackendSignSessionBody, - BackendSignatureResponse, + ArgentServiceSessionBody, + ArgentServiceSignSessionBody, + ArgentServiceSignatureResponse, OffChainSession, } from "./sessionTypes" import { getSessionTypedData } from "./utils" -export class ArgentBackendSessionService { +export class ArgentSessionService { constructor( public pubkey: string, private accountSessionSignature: Signature, - private argentBackendBaseUrl = ARGENT_BACKEND_BASE_URL, + private argentSessionServiceBaseUrl = ARGENT_SESSION_SERVICE_BASE_URL, ) {} public async signTxAndSession( @@ -35,7 +35,7 @@ export class ArgentBackendSessionService { sessionTypedData: TypedData, sessionSignature: bigint[], cacheAuthorisation: boolean, - ): Promise { + ): Promise { const compiledCalldata = transaction.getExecuteCalldata( calls, transactionsDetail.cairoVersion, @@ -50,7 +50,7 @@ export class ArgentBackendSessionService { this.accountSessionSignature, ) - const session: BackendSessionBody = { + const session: ArgentServiceSessionBody = { sessionHash, sessionAuthorisation, cacheAuthorisation, @@ -64,7 +64,7 @@ export class ArgentBackendSessionService { }, } - const body: BackendSignSessionBody = { + const body: ArgentServiceSignSessionBody = { session, } @@ -119,7 +119,7 @@ export class ArgentBackendSessionService { } const response = await fetch( - `${this.argentBackendBaseUrl}/cosigner/signSession`, + `${this.argentSessionServiceBaseUrl}/cosigner/signSession`, { method: "POST", headers: { @@ -145,7 +145,7 @@ export class ArgentBackendSessionService { sessionSignature: bigint[], cacheAuthorisation: boolean, chainId: StarknetChainId, - ): Promise { + ): Promise { const sessionMessageHash = typedData.getMessageHash( getSessionTypedData(sessionTokenToSign, chainId), accountAddress, @@ -155,7 +155,7 @@ export class ArgentBackendSessionService { this.accountSessionSignature, ) - const session: BackendSessionBody = { + const session: ArgentServiceSessionBody = { sessionHash: sessionMessageHash, sessionAuthorisation, cacheAuthorisation, @@ -187,7 +187,7 @@ export class ArgentBackendSessionService { ) const response = await fetch( - `${this.argentBackendBaseUrl}/cosigner/signSessionEFO`, + `${this.argentSessionServiceBaseUrl}/cosigner/signSessionEFO`, { method: "POST", headers: { diff --git a/src/constants.ts b/src/constants.ts index 8667fa9..b436613 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1 +1 @@ -export const ARGENT_BACKEND_BASE_URL = "https://cloud.argent-api.com/v1" +export const ARGENT_SESSION_SERVICE_BASE_URL = "https://cloud.argent-api.com/v1" diff --git a/src/main.ts b/src/main.ts index 532b60e..91ac5bf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,7 +2,7 @@ export * from "./utils" export type * from "./sessionTypes" export * from "./outsideExecution" -export { ArgentBackendSessionService } from "./sessionBackendService" +export { ArgentSessionService } from "./argentSessionService" export { SessionDappService } from "./sessionDappService" export { type SignSessionError } from "./errors" diff --git a/src/sessionDappService.ts b/src/sessionDappService.ts index 96db3cc..ef17d06 100644 --- a/src/sessionDappService.ts +++ b/src/sessionDappService.ts @@ -31,9 +31,9 @@ import { getOutsideCall, getOutsideExecutionTypedData, } from "./outsideExecution" -import { ArgentBackendSessionService } from "./sessionBackendService" +import { ArgentSessionService } from "./argentSessionService" import { - BackendSignatureResponse, + ArgentServiceSignatureResponse, DappKey, OffChainSession, OnChainSession, @@ -68,7 +68,7 @@ class SessionSigner extends Signer { export class SessionDappService { constructor( - private argentBackend: ArgentBackendSessionService, + private argentSessionService: ArgentSessionService, public chainId: StarknetChainId, private dappKey: DappKey, ) {} @@ -173,7 +173,7 @@ export class SessionDappService { cacheAuthorisation, ) - const guardianSignature = await this.argentBackend.signTxAndSession( + const guardianSignature = await this.argentSessionService.signTxAndSession( calls, invocationSignerDetails, sessionTypedData, @@ -279,7 +279,7 @@ export class SessionDappService { calls: Call[], sessionSignature: bigint[], session_authorization: string[], - guardianSignature: BackendSignatureResponse, + guardianSignature: ArgentServiceSignatureResponse, cache_authorization: boolean, ) { return { @@ -380,7 +380,6 @@ export class SessionDappService { await this.getSessionSignatureForOutsideExecutionTypedData( sessionAuthorizationSignature, sessionRequest, - messageHash, calls, accountAddress, outsideExecutionTypedData, @@ -417,7 +416,7 @@ export class SessionDappService { cacheAuthorisation, ) - const guardianSignature = await this.argentBackend.signSessionEFO( + const guardianSignature = await this.argentSessionService.signSessionEFO( sessionRequest, accountAddress, outsideExecutionTypedData, @@ -463,7 +462,6 @@ export class SessionDappService { await this.getSessionSignatureForOutsideExecutionTypedData( sessionAuthorizationSignature, sessionRequest, - messageHash, calls, accountAddress, currentTypedData, diff --git a/src/sessionTypes.ts b/src/sessionTypes.ts index 1c8daeb..f441a69 100644 --- a/src/sessionTypes.ts +++ b/src/sessionTypes.ts @@ -78,16 +78,16 @@ export type CreateSessionParams = { chainId: StarknetChainId sessionRequest: OffChainSession useCacheAuthorisation?: boolean - argentBackendBaseUrl?: string + argentSessionServiceBaseUrl?: string } -export type BackendSignatureResponse = { +export type ArgentServiceSignatureResponse = { publicKey: string // Public address of a guardian (cosigner) r: bigint s: bigint } -export type BackendSessionBody = { +export type ArgentServiceSessionBody = { sessionHash: string sessionAuthorisation: ArraySignatureType cacheAuthorisation?: boolean @@ -101,7 +101,7 @@ export type BackendSessionBody = { } } -export type BackendSessionTxV1Body = { +export type ArgentServiceSessionTxV1Body = { contractAddress: string calldata: Calldata maxFee: string @@ -110,7 +110,7 @@ export type BackendSessionTxV1Body = { chainId: string } -export type BackendSessionTxV3Body = { +export type ArgentServiceSessionTxV3Body = { sender_address: string calldata: Calldata nonce: string @@ -133,7 +133,7 @@ export type BackendSessionTxV3Body = { fee_data_availability_mode: string } -export type BackendSignSessionBody = { - session: BackendSessionBody - transaction?: BackendSessionTxV1Body | BackendSessionTxV3Body +export type ArgentServiceSignSessionBody = { + session: ArgentServiceSessionBody + transaction?: ArgentServiceSessionTxV1Body | ArgentServiceSessionTxV3Body } diff --git a/src/utils.ts b/src/utils.ts index efc8838..84f675a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,7 +5,7 @@ import { StarknetWindowObject, TypedData, } from "starknet-types" -import { ArgentBackendSessionService } from "./sessionBackendService" +import { ArgentSessionService } from "./argentSessionService" import { SessionDappService } from "./sessionDappService" import { AllowedMethod, @@ -87,16 +87,16 @@ const buildSessionAccount = async ({ chainId, address, dappKey, - argentBackendBaseUrl, + argentSessionServiceBaseUrl, }: CreateSessionParams): Promise => { - const argentBackendService = new ArgentBackendSessionService( + const argentSessionService = new ArgentSessionService( dappKey.publicKey, accountSessionSignature, - argentBackendBaseUrl, + argentSessionServiceBaseUrl, ) const dappService = new SessionDappService( - argentBackendService, + argentSessionService, chainId, dappKey, )