Skip to content

Commit

Permalink
Add endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Oct 19, 2023
1 parent 69296ef commit 9c9243d
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
76 changes: 76 additions & 0 deletions packages/api-kit/src/SafeApiKit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
AddMessageProps,
AddSafeDelegateProps,
AllTransactionsListResponse,
AllTransactionsOptions,
DeleteSafeDelegateProps,
GetSafeDelegateProps,
GetSafeMessageListProps,
MasterCopyResponse,
ModulesResponse,
OwnerResponse,
Expand All @@ -12,6 +14,8 @@ import {
SafeDelegateListResponse,
SafeDelegateResponse,
SafeInfoResponse,
SafeMessage,
SafeMessageListResponse,
SafeModuleTransactionListResponse,
SafeMultisigTransactionEstimate,
SafeMultisigTransactionEstimateResponse,
Expand Down Expand Up @@ -599,6 +603,78 @@ class SafeApiKit {
method: HttpMethod.Get
})
}

async getMessage(messageHash: string): Promise<SafeMessage> {
if (!messageHash) {
throw new Error('Invalid messageHash')
}

return sendRequest({
url: `${this.#txServiceBaseUrl}/v1/messages/${messageHash}/`,
method: HttpMethod.Get
})
}

async addMessageSignature(messageHash: string, signature: string): Promise<void> {
if (!messageHash || !signature) {
throw new Error('Invalid messageHash or signature')
}

return sendRequest({
url: `${this.#txServiceBaseUrl}/v1/messages/${messageHash}/signatures/`,
method: HttpMethod.Post,
body: {
signature
}
})
}

async getMessages(
safeAddress: string,
{ ordering, limit, offset }: GetSafeMessageListProps
): Promise<SafeMessageListResponse> {
if (!safeAddress) {
throw new Error('Invalid safeAddress')
}

const url = new URL(`${this.#txServiceBaseUrl}/v1/safes/${safeAddress}/messages/`)

if (ordering) {
url.searchParams.set('ordering', ordering)
}

if (limit) {
url.searchParams.set('limit', limit)
}

if (offset) {
url.searchParams.set('offset', offset)
}

return sendRequest({
url: url.toString(),
method: HttpMethod.Get
})
}

async addMessage(
safeAddress: string,
{ message, safeAppId, signature }: AddMessageProps
): Promise<void> {
if (!safeAddress) {
throw new Error('Invalid safeAddress')
}

return sendRequest({
url: `${this.#txServiceBaseUrl}/v1/safes/${safeAddress}/messages/`,
method: HttpMethod.Post,
body: {
message,
safeAppId: safeAppId || 0,
signature
}
})
}
}

export default SafeApiKit
62 changes: 62 additions & 0 deletions packages/api-kit/src/types/safeTransactionServiceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,65 @@ export type AllTransactionsListResponse = {
export type ModulesResponse = {
safes: string[]
}

export type SafeMessageConfirmation = {
readonly created: string
readonly modified: string
readonly owner: string
readonly signature: string
readonly signatureType: string
}

export type SafeMessage = {
readonly created: string
readonly modified: string
readonly safe: string
readonly messageHash: string
readonly message: string
readonly proposedBy: string
readonly safeAppId: null | string
readonly confirmations: Array<SafeMessageConfirmation>
readonly preparedSignature: string
}

export type SafeMessageListResponse = {
readonly count: number
readonly next?: string
readonly previous?: string
readonly results: SafeMessage[]
}

export type GetSafeMessageListProps = {
ordering?: string
limit?: string
offset?: string
}

interface TypedDataDomain {
name?: string
version?: string
chainId?: unknown // BigNumberish
verifyingContract?: string
salt?: ArrayLike<number> | string // BytesLike
}

interface TypedDataTypes {
name: string
type: string
}

type TypedMessageTypes = {
[key: string]: TypedDataTypes[]
}

export type EIP712TypedData = {
domain: TypedDataDomain
types: TypedMessageTypes
message: Record<string, unknown>
}

export type AddMessageProps = {
message: string | EIP712TypedData
safeAppId: number
signature: string
}

0 comments on commit 9c9243d

Please sign in to comment.