Skip to content

Commit

Permalink
Merge branch 'waas' of github.com:0xsequence/sequence.js into waas
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Oct 27, 2023
2 parents 564b807 + 474c816 commit da36f24
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
21 changes: 19 additions & 2 deletions packages/waas/src/payloads/packets/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import { ethers } from "ethers"
import { BasePacket } from ".."

export type SignMessagePacket = BasePacket & {
wallet: string;
network: string;

message: string
}

export function signMessage(wallet: string, chainId: number, message: string): SignMessagePacket {
return {
code: 'signMessage',
wallet: wallet,
network: chainId.toString(),
message: message.startsWith('0x') ?
message : ethers.utils.hexlify(ethers.utils.toUtf8Bytes(message))
}
}

export type TransactionsPacket = BasePacket & {
wallet: string;
network: string;

transactions: TransactionSubpacket[]
}

export type TransactionSubpacket =
export type TransactionSubpacket =
RawTransactionSubpacket |
SendERC20Subpacket |
SendERC721Subpacket |
SendERC1155Subpacket
SendERC1155Subpacket


export type RawTransactionSubpacket = {
Expand Down
39 changes: 29 additions & 10 deletions packages/waas/src/sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from "ethers"
import { SessionPacket, SessionPacketProof, ValidateSessionPacket, openSession } from "./payloads/packets/session"
import { LocalStore, Store, StoreObj } from "./store"
import { BasePacket, Payload, signPacket } from "./payloads"
import { TransactionsPacket, combinePackets, sendERC1155, sendERC20, sendERC721, sendTransactions } from "./payloads/packets/wallet"
import { SignMessagePacket, TransactionsPacket, signMessage, combinePackets, sendERC1155, sendERC20, sendERC721, sendTransactions } from "./payloads/packets/wallet"
import { OpenSessionResponse } from "./payloads/responses"
import { Guard } from "./clients/guard.gen"
import { DEFAULTS } from "./defaults"
Expand Down Expand Up @@ -49,7 +49,7 @@ export class Sequence {
/**
* Builds a payload that can be sent to the WaaS API to sign a transaction.
* It automatically signs the payload, and attaches the current wallet address.
*
*
* @param packet The action already packed into a packet
* @returns A payload that can be sent to the WaaS API
*/
Expand Down Expand Up @@ -100,11 +100,11 @@ export class Sequence {
* This method will initiate a sign-in process with the waas API. It must be performed
* when the user wants to sign in to the app, in parallel with the authentication of the
* application's own authentication system.
*
*
* This method begins the sign-in process, but does not complete it. The returned payload
* must be sent to the waas API to complete the sign-in. The waas API will return a receipt
* that must be sent to the `completeSignIn` method to complete the sign-in.
*
* that must be sent to the `completeSignIn` method to complete the sign-in.
*
* @param proof Information about the user that can be used to prove their identity
* @returns a session payload that **must** be sent to the waas API to complete the sign-in
* @throws {Error} If the session is already signed in or there is a pending sign-in
Expand Down Expand Up @@ -135,12 +135,12 @@ export class Sequence {
/**
* This method will complete a sign-in process with the waas API. It must be performed
* after the `signIn` method, when the waas API has returned a receipt.
*
*
* This method completes the sign-in process by validating the receipt's proof.
* If the proof is invalid or there is no pending sign-in, it will throw an error.
*
*
* After this method is called, the wallet is ready to be used to sign transactions.
*
*
* @param receipt The receipt returned by the waas API after the `signIn` method
* @returns The wallet address of the user that signed in
* @throws {Error} If there is no pending sign-in or the receipt is invalid
Expand Down Expand Up @@ -183,13 +183,32 @@ export class Sequence {
// Signer methods
//

/**
* This method can be used to sign message using waas API. It can only be used
* after successfully signing in with the `signIn` and `completeSignIn` methods.
*
* The method does not sign the message. It only returns a payload
* that must be sent to the waas API to complete the sign process.
*
* @param chainId The network on which the message will be signed
* @param message The message that will be signed
* @return a payload that must be sent to the waas API to complete sign process
*/
async signMessage(
chainId: number,
message: string
): Promise<Payload<SignMessagePacket>> {
const packet = signMessage(await this.getWalletAddress(), chainId, message)
return this.buildPayload(packet)
}

/**
* This method can be used to send transactions to the waas API. It can only be used
* after successfully signing in with the `signIn` and `completeSignIn` methods.
*
*
* The method does not send the transactions to the network. It only returns a payload
* that must be sent to the waas API to complete the transaction.
*
*
* @param transactions The transactions to be sent
* @param chainId The network on which the transactions will be sent
* @returns a payload that must be sent to the waas API to complete the transaction
Expand Down

0 comments on commit da36f24

Please sign in to comment.