Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.tabSize": 2,
"editor.hover.enabled": true,
"editor.hover.enabled": "on",
"typescript.validate.enable": true,
"javascript.validate.enable": true,
"editor.defaultFormatter": "oxc.oxc-vscode",
Expand Down
2 changes: 1 addition & 1 deletion examples/fee-payer-and-webauthn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"check:types": "tsc -b --noEmit",
"dev": "vp dev",
"gen:types": "wrangler types",
"postinstall": "[ -f .env ] || cp .env.example .env && wrangler types",
"postinstall": "node -e \"const fs=require('fs');if(!fs.existsSync('.env'))fs.copyFileSync('.env.example','.env')\" && wrangler types",
"build": "tsc -b && vp build",
"preview": "vp preview"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/fee-payer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"check:types": "tsc -b --noEmit",
"dev": "vp dev",
"gen:types": "wrangler types",
"postinstall": "[ -f .env ] || cp .env.example .env && wrangler types",
"postinstall": "node -e \"const fs=require('fs');if(!fs.existsSync('.env'))fs.copyFileSync('.env.example','.env')\" && wrangler types",
"build": "tsc -b && vp build",
"preview": "vp preview"
},
Expand Down
25 changes: 19 additions & 6 deletions src/core/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,15 +1048,28 @@ export function create(options: create.Options = {}): create.ReturnType {
// Skip polyfill on runtimes where `globalThis.fetch` is read-only (e.g.
// Cloudflare Workers). Caller can also explicitly opt out via `mpp.polyfill`.
const polyfill = polyfill_option ?? isFetchWritable()
const getClient = ({ chainId }: { chainId?: number | undefined }) => {
const getClient = async ({ chainId }: { chainId?: number | undefined }) => {
const client = provider.getClient({ chainId })
const account = store.getState().accounts[store.getState().activeAccount]
const state = store.getState()
const account = state.accounts[state.activeAccount]
if (!account) throw new ox_Provider.DisconnectedError({ message: 'No active account.' })
const resolvedChainId = chainId ?? state.chainId
const accessKey = await AccessKey.select({
account: account.address,
chainId: resolvedChainId,
store,
})
return Object.assign(client, {
account: {
address: account.address,
type: 'json-rpc' as const,
},
account: accessKey
? {
address: account.address,
accessKeyAddress: accessKey.address,
type: 'json-rpc' as const,
}
: {
address: account.address,
type: 'json-rpc' as const,
},
})
}
Mppx.create({
Expand Down
21 changes: 21 additions & 0 deletions src/core/mppx.localnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,27 @@ describe('mppx integration', () => {
}
})

test('mpp client uses access key address as authorizedSigner', async () => {
const provider = Provider.create({
adapter: headlessWebAuthn(),
chains: [chain],
mpp: { mode: 'push' },
})
const address = await connect(provider)
await fund(address)

await provider.request({
method: 'wallet_authorizeAccessKey',
params: [{ expiry: Expiry.days(1) }],
})

const key = provider.store.getState().accessKeys[0]!
expect(key).toBeDefined()

const res = await fetch(`${server.url}/fortune`)
expect(res.status).toBe(200)
})

test('push mode publishes pending access key authorization', async () => {
const provider = Provider.create({
adapter: headlessWebAuthn(),
Expand Down