Skip to content

Commit 51ccfa7

Browse files
authored
Merge branch 'master' into test-wdk
2 parents 4fc6489 + 1c00450 commit 51ccfa7

23 files changed

Lines changed: 816 additions & 404 deletions

packages/wallet/core/.env.test

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/wallet/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@repo/typescript-config": "workspace:^",
1919
"@types/node": "^22.13.9",
2020
"dotenv": "^16.4.7",
21+
"fake-indexeddb": "^6.0.0",
2122
"typescript": "^5.7.3",
2223
"vitest": "^3.1.2"
2324
},

packages/wallet/core/src/wallet.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Address as SequenceAddress,
88
Signature as SequenceSignature,
99
} from '@0xsequence/wallet-primitives'
10-
import { AbiFunction, Address, Bytes, Hex, Provider } from 'ox'
10+
import { AbiFunction, Address, Bytes, Hex, Provider, TypedData } from 'ox'
1111
import * as Envelope from './envelope.js'
1212
import * as State from './state/index.js'
1313

@@ -343,6 +343,41 @@ export class Wallet {
343343
}
344344
}
345345

346+
async prepareMessageSignature(
347+
message: string | Hex.Hex | Payload.TypedDataToSign,
348+
chainId: bigint,
349+
): Promise<Envelope.Envelope<Payload.Message>> {
350+
let encodedMessage: Hex.Hex
351+
if (typeof message !== 'string') {
352+
encodedMessage = TypedData.encode(message)
353+
} else {
354+
let hexMessage = Hex.validate(message) ? message : Hex.fromString(message)
355+
const messageSize = Hex.size(hexMessage)
356+
encodedMessage = Hex.concat(Hex.fromString(`${`\x19Ethereum Signed Message:\n${messageSize}`}`), hexMessage)
357+
}
358+
return {
359+
...(await this.prepareBlankEnvelope(chainId)),
360+
payload: Payload.fromMessage(encodedMessage),
361+
}
362+
}
363+
364+
async buildMessageSignature(
365+
envelope: Envelope.Signed<Payload.Message>,
366+
provider?: Provider.Provider,
367+
): Promise<Bytes.Bytes> {
368+
const status = await this.getStatus(provider)
369+
const signature = Envelope.encodeSignature(envelope)
370+
if (!status.isDeployed) {
371+
const deployTransaction = await this.buildDeployTransaction()
372+
signature.erc6492 = { to: deployTransaction.to, data: Bytes.fromHex(deployTransaction.data) }
373+
}
374+
const encoded = SequenceSignature.encodeSignature({
375+
...signature,
376+
suffix: status.pendingUpdates.map(({ signature }) => signature),
377+
})
378+
return encoded
379+
}
380+
346381
private async prepareBlankEnvelope(chainId: bigint) {
347382
const status = await this.getStatus()
348383

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { config as dotenvConfig } from 'dotenv'
2-
import { Abi, Address } from 'ox'
2+
import { Abi, AbiEvent, Address } from 'ox'
33

44
const envFile = process.env.CI ? '.env.test' : '.env.test.local'
55
dotenvConfig({ path: envFile })
66

77
export const EMITTER_ADDRESS: Address.Address = '0x7F6e420Ed3017A36bE6e1DA8e3AFE61569eb4840'
8-
export const EMITTER_ABI = Abi.from(['function explicitEmit()', 'function implicitEmit()'])
8+
export const EMITTER_FUNCTIONS = Abi.from(['function explicitEmit()', 'function implicitEmit()'])
9+
export const EMITTER_EVENT_TOPICS = [
10+
AbiEvent.encode(AbiEvent.from('event Explicit(address sender)')).topics[0],
11+
AbiEvent.encode(AbiEvent.from('event Implicit(address sender)')).topics[0],
12+
]
913

1014
// Environment variables
11-
export const { RPC_URL, PRIVATE_KEY } = process.env
12-
export const CAN_RUN_LIVE = !!RPC_URL && !!PRIVATE_KEY
15+
export const LOCAL_RPC_URL = process.env.LOCAL_RPC_URL || 'http://localhost:8545'

0 commit comments

Comments
 (0)