@0xsequence/wallet-core 3.0.0-beta.9 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test.log +290 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CHANGELOG.md +158 -0
- package/dist/bundler/bundlers/pimlico.d.ts +3 -2
- package/dist/bundler/bundlers/pimlico.d.ts.map +1 -1
- package/dist/bundler/bundlers/pimlico.js +9 -3
- package/dist/env.d.ts +22 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +42 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/signers/index.d.ts +1 -1
- package/dist/signers/passkey.d.ts +11 -3
- package/dist/signers/passkey.d.ts.map +1 -1
- package/dist/signers/passkey.js +12 -6
- package/dist/signers/pk/encrypted.d.ts +13 -2
- package/dist/signers/pk/encrypted.d.ts.map +1 -1
- package/dist/signers/pk/encrypted.js +94 -15
- package/dist/signers/pk/index.d.ts +1 -1
- package/dist/signers/session/explicit.d.ts.map +1 -1
- package/dist/signers/session/explicit.js +5 -8
- package/dist/signers/session/implicit.d.ts.map +1 -1
- package/dist/signers/session/implicit.js +1 -1
- package/dist/signers/session/session.d.ts +1 -0
- package/dist/signers/session/session.d.ts.map +1 -1
- package/dist/signers/session/session.js +7 -0
- package/dist/signers/session-manager.d.ts +4 -0
- package/dist/signers/session-manager.d.ts.map +1 -1
- package/dist/signers/session-manager.js +65 -22
- package/dist/state/local/index.d.ts.map +1 -1
- package/dist/state/local/index.js +3 -2
- package/dist/state/local/indexed-db.d.ts +4 -1
- package/dist/state/local/indexed-db.d.ts.map +1 -1
- package/dist/state/local/indexed-db.js +12 -2
- package/dist/state/remote/dev-http.d.ts +2 -1
- package/dist/state/remote/dev-http.d.ts.map +1 -1
- package/dist/state/remote/dev-http.js +11 -5
- package/dist/state/sequence/index.d.ts +2 -1
- package/dist/state/sequence/index.d.ts.map +1 -1
- package/dist/state/sequence/index.js +14 -5
- package/dist/wallet.js +2 -2
- package/eslint.config.js +12 -0
- package/package.json +12 -10
- package/src/bundler/bundlers/pimlico.ts +10 -4
- package/src/env.ts +68 -0
- package/src/index.ts +1 -0
- package/src/signers/index.ts +1 -1
- package/src/signers/passkey.ts +21 -5
- package/src/signers/pk/encrypted.ts +103 -14
- package/src/signers/pk/index.ts +1 -1
- package/src/signers/session/explicit.ts +5 -20
- package/src/signers/session/implicit.ts +1 -2
- package/src/signers/session/session.ts +10 -2
- package/src/signers/session-manager.ts +82 -25
- package/src/state/local/index.ts +4 -2
- package/src/state/local/indexed-db.ts +15 -2
- package/src/state/remote/dev-http.ts +11 -5
- package/src/state/sequence/index.ts +15 -6
- package/src/wallet.ts +2 -2
- package/test/constants.ts +4 -0
- package/test/envelope.test.ts +0 -1
- package/test/session-manager.test.ts +345 -3
- package/test/signers-pk.test.ts +1 -1
- package/test/signers-session-implicit.test.ts +0 -2
- package/test/state/debug.test.ts +2 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Extensions } from '@0xsequence/wallet-primitives'
|
|
1
|
+
import { Constants, Extensions } from '@0xsequence/wallet-primitives'
|
|
2
2
|
import { AbiEvent, AbiFunction, Address, Bytes, Hex, Provider, RpcTransport, Secp256k1 } from 'ox'
|
|
3
3
|
import { describe, expect, it } from 'vitest'
|
|
4
4
|
import { Attestation, GenericTree, Payload, Permission, SessionConfig } from '../../primitives/src/index.js'
|
|
@@ -731,7 +731,7 @@ for (const extension of ALL_EXTENSIONS) {
|
|
|
731
731
|
)
|
|
732
732
|
|
|
733
733
|
it(
|
|
734
|
-
'signs a payload using an explicit session',
|
|
734
|
+
'signs a payload using an explicit session with allowAll and value limit',
|
|
735
735
|
async () => {
|
|
736
736
|
const provider = Provider.from(RpcTransport.fromHttp(LOCAL_RPC_URL))
|
|
737
737
|
const chainId = Number(await provider.request({ method: 'eth_chainId' }))
|
|
@@ -804,7 +804,7 @@ for (const extension of ALL_EXTENSIONS) {
|
|
|
804
804
|
)
|
|
805
805
|
|
|
806
806
|
it(
|
|
807
|
-
'signs
|
|
807
|
+
'signs using explicit session with onlyOnce, consumes usage and rejects second call',
|
|
808
808
|
async () => {
|
|
809
809
|
const provider = Provider.from(RpcTransport.fromHttp(LOCAL_RPC_URL))
|
|
810
810
|
const chainId = Number(await provider.request({ method: 'eth_chainId' }))
|
|
@@ -1357,5 +1357,347 @@ for (const extension of ALL_EXTENSIONS) {
|
|
|
1357
1357
|
},
|
|
1358
1358
|
timeout,
|
|
1359
1359
|
)
|
|
1360
|
+
|
|
1361
|
+
it(
|
|
1362
|
+
'two explicit sessions with same value limit: exhaust first then second send uses second session (increment from non-increment calls only)',
|
|
1363
|
+
async () => {
|
|
1364
|
+
const provider = Provider.from(RpcTransport.fromHttp(LOCAL_RPC_URL))
|
|
1365
|
+
const chainId = Number(await provider.request({ method: 'eth_chainId' }))
|
|
1366
|
+
|
|
1367
|
+
const identityPrivateKey = Secp256k1.randomPrivateKey()
|
|
1368
|
+
const identityAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey: identityPrivateKey }))
|
|
1369
|
+
const stateProvider = new State.Local.Provider()
|
|
1370
|
+
|
|
1371
|
+
const targetAddress = randomAddress()
|
|
1372
|
+
const valueLimit = 500000000000000000n // 0.5 ETH per session
|
|
1373
|
+
|
|
1374
|
+
const sessionPermission: ExplicitSessionConfig = {
|
|
1375
|
+
chainId,
|
|
1376
|
+
valueLimit,
|
|
1377
|
+
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
1378
|
+
permissions: [PermissionBuilder.for(targetAddress).allowAll().build()],
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
const explicitPrivateKey1 = Secp256k1.randomPrivateKey()
|
|
1382
|
+
const explicitSigner1 = new Signers.Session.Explicit(explicitPrivateKey1, {
|
|
1383
|
+
...sessionPermission,
|
|
1384
|
+
})
|
|
1385
|
+
|
|
1386
|
+
const explicitPrivateKey2 = Secp256k1.randomPrivateKey()
|
|
1387
|
+
const explicitSigner2 = new Signers.Session.Explicit(explicitPrivateKey2, {
|
|
1388
|
+
...sessionPermission,
|
|
1389
|
+
})
|
|
1390
|
+
|
|
1391
|
+
let sessionTopology = SessionConfig.addExplicitSession(SessionConfig.emptySessionsTopology(identityAddress), {
|
|
1392
|
+
...sessionPermission,
|
|
1393
|
+
signer: explicitSigner1.address,
|
|
1394
|
+
})
|
|
1395
|
+
sessionTopology = SessionConfig.addExplicitSession(sessionTopology, {
|
|
1396
|
+
...sessionPermission,
|
|
1397
|
+
signer: explicitSigner2.address,
|
|
1398
|
+
})
|
|
1399
|
+
await stateProvider.saveTree(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
|
|
1400
|
+
const imageHash = GenericTree.hash(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
|
|
1401
|
+
|
|
1402
|
+
const wallet = await Wallet.fromConfiguration(
|
|
1403
|
+
{
|
|
1404
|
+
threshold: 1n,
|
|
1405
|
+
checkpoint: 0n,
|
|
1406
|
+
topology: [{ type: 'sapient-signer', address: extension.sessions, weight: 1n, imageHash }, Hex.random(32)],
|
|
1407
|
+
},
|
|
1408
|
+
{ stateProvider },
|
|
1409
|
+
)
|
|
1410
|
+
// Fund wallet with 2 ETH so we can send 0.5 ETH twice (each tx needs value + gas)
|
|
1411
|
+
await provider.request({
|
|
1412
|
+
method: 'anvil_setBalance',
|
|
1413
|
+
params: [wallet.address, Hex.fromNumber(2n * 1000000000000000000n)],
|
|
1414
|
+
})
|
|
1415
|
+
|
|
1416
|
+
const sessionManager = new Signers.SessionManager(wallet, {
|
|
1417
|
+
provider,
|
|
1418
|
+
sessionManagerAddress: extension.sessions,
|
|
1419
|
+
explicitSigners: [explicitSigner1, explicitSigner2],
|
|
1420
|
+
})
|
|
1421
|
+
|
|
1422
|
+
const call: Payload.Call = {
|
|
1423
|
+
to: targetAddress,
|
|
1424
|
+
value: valueLimit, // one full limit
|
|
1425
|
+
data: '0x' as Hex.Hex,
|
|
1426
|
+
gasLimit: 0n,
|
|
1427
|
+
delegateCall: false,
|
|
1428
|
+
onlyFallback: false,
|
|
1429
|
+
behaviorOnError: 'revert',
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
// First send: uses first session (exhausts it)
|
|
1433
|
+
const increment1 = await sessionManager.prepareIncrement(wallet.address, chainId, [call])
|
|
1434
|
+
expect(increment1).not.toBeNull()
|
|
1435
|
+
const calls1 = includeIncrement([call], increment1!, extension.sessions)
|
|
1436
|
+
const tx1 = await buildAndSignCall(wallet, sessionManager, calls1, provider, chainId)
|
|
1437
|
+
await simulateTransaction(provider, tx1)
|
|
1438
|
+
|
|
1439
|
+
// Second send: same call. First session is exhausted so findSignersForCalls picks second session.
|
|
1440
|
+
// Payload is [call, increment] (or [increment, call]). signSapient must derive expectedIncrement
|
|
1441
|
+
// from non-increment calls only so it matches the increment we built for the second session.
|
|
1442
|
+
const increment2 = await sessionManager.prepareIncrement(wallet.address, chainId, [call])
|
|
1443
|
+
expect(increment2).not.toBeNull()
|
|
1444
|
+
const calls2 = includeIncrement([call], increment2!, extension.sessions)
|
|
1445
|
+
const tx2 = await buildAndSignCall(wallet, sessionManager, calls2, provider, chainId)
|
|
1446
|
+
await simulateTransaction(provider, tx2)
|
|
1447
|
+
},
|
|
1448
|
+
timeout,
|
|
1449
|
+
)
|
|
1450
|
+
|
|
1451
|
+
describe('increment built from non-increment calls only', () => {
|
|
1452
|
+
it(
|
|
1453
|
+
'prepareIncrement returns null when calls contain only an increment call (no non-increment calls)',
|
|
1454
|
+
async () => {
|
|
1455
|
+
const provider = Provider.from(RpcTransport.fromHttp(LOCAL_RPC_URL))
|
|
1456
|
+
const chainId = Number(await provider.request({ method: 'eth_chainId' }))
|
|
1457
|
+
|
|
1458
|
+
const identityPrivateKey = Secp256k1.randomPrivateKey()
|
|
1459
|
+
const identityAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey: identityPrivateKey }))
|
|
1460
|
+
const stateProvider = new State.Local.Provider()
|
|
1461
|
+
|
|
1462
|
+
const sessionPermission: ExplicitSessionConfig = {
|
|
1463
|
+
chainId,
|
|
1464
|
+
valueLimit: 0n,
|
|
1465
|
+
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
1466
|
+
permissions: [PermissionBuilder.for(EMITTER_ADDRESS1).allowAll().build()],
|
|
1467
|
+
}
|
|
1468
|
+
const explicitSigner = new Signers.Session.Explicit(Secp256k1.randomPrivateKey(), sessionPermission)
|
|
1469
|
+
const sessionTopology = SessionConfig.addExplicitSession(
|
|
1470
|
+
SessionConfig.emptySessionsTopology(identityAddress),
|
|
1471
|
+
{
|
|
1472
|
+
...sessionPermission,
|
|
1473
|
+
signer: explicitSigner.address,
|
|
1474
|
+
},
|
|
1475
|
+
)
|
|
1476
|
+
await stateProvider.saveTree(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
|
|
1477
|
+
const imageHash = GenericTree.hash(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
|
|
1478
|
+
|
|
1479
|
+
const wallet = await Wallet.fromConfiguration(
|
|
1480
|
+
{
|
|
1481
|
+
threshold: 1n,
|
|
1482
|
+
checkpoint: 0n,
|
|
1483
|
+
topology: [
|
|
1484
|
+
{ type: 'sapient-signer', address: extension.sessions, weight: 1n, imageHash },
|
|
1485
|
+
Hex.random(32),
|
|
1486
|
+
],
|
|
1487
|
+
},
|
|
1488
|
+
{ stateProvider },
|
|
1489
|
+
)
|
|
1490
|
+
const sessionManager = new Signers.SessionManager(wallet, {
|
|
1491
|
+
provider,
|
|
1492
|
+
sessionManagerAddress: extension.sessions,
|
|
1493
|
+
explicitSigners: [explicitSigner],
|
|
1494
|
+
})
|
|
1495
|
+
|
|
1496
|
+
// Only an increment call (no non-increment calls). Contract would reject payload with only self-call; we return null.
|
|
1497
|
+
const incrementOnlyCall: Payload.Call = {
|
|
1498
|
+
to: extension.sessions,
|
|
1499
|
+
data: AbiFunction.encodeData(Constants.INCREMENT_USAGE_LIMIT, [[]]),
|
|
1500
|
+
value: 0n,
|
|
1501
|
+
gasLimit: 0n,
|
|
1502
|
+
delegateCall: false,
|
|
1503
|
+
onlyFallback: false,
|
|
1504
|
+
behaviorOnError: 'revert',
|
|
1505
|
+
}
|
|
1506
|
+
const result = await sessionManager.prepareIncrement(wallet.address, chainId, [incrementOnlyCall])
|
|
1507
|
+
expect(result).toBeNull()
|
|
1508
|
+
},
|
|
1509
|
+
timeout,
|
|
1510
|
+
)
|
|
1511
|
+
|
|
1512
|
+
it(
|
|
1513
|
+
'prepareIncrement([increment, nonIncrementCall]) produces same increment data as prepareIncrement([nonIncrementCall])',
|
|
1514
|
+
async () => {
|
|
1515
|
+
const provider = Provider.from(RpcTransport.fromHttp(LOCAL_RPC_URL))
|
|
1516
|
+
const chainId = Number(await provider.request({ method: 'eth_chainId' }))
|
|
1517
|
+
|
|
1518
|
+
const identityPrivateKey = Secp256k1.randomPrivateKey()
|
|
1519
|
+
const identityAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey: identityPrivateKey }))
|
|
1520
|
+
const stateProvider = new State.Local.Provider()
|
|
1521
|
+
|
|
1522
|
+
const sessionPermission: ExplicitSessionConfig = {
|
|
1523
|
+
chainId,
|
|
1524
|
+
valueLimit: 0n,
|
|
1525
|
+
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
1526
|
+
permissions: [PermissionBuilder.for(EMITTER_ADDRESS1).forFunction(EMITTER_FUNCTIONS[0]).onlyOnce().build()],
|
|
1527
|
+
}
|
|
1528
|
+
const explicitSigner = new Signers.Session.Explicit(Secp256k1.randomPrivateKey(), sessionPermission)
|
|
1529
|
+
const sessionTopology = SessionConfig.addExplicitSession(
|
|
1530
|
+
SessionConfig.emptySessionsTopology(identityAddress),
|
|
1531
|
+
{
|
|
1532
|
+
...sessionPermission,
|
|
1533
|
+
signer: explicitSigner.address,
|
|
1534
|
+
},
|
|
1535
|
+
)
|
|
1536
|
+
await stateProvider.saveTree(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
|
|
1537
|
+
const imageHash = GenericTree.hash(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
|
|
1538
|
+
|
|
1539
|
+
const wallet = await Wallet.fromConfiguration(
|
|
1540
|
+
{
|
|
1541
|
+
threshold: 1n,
|
|
1542
|
+
checkpoint: 0n,
|
|
1543
|
+
topology: [
|
|
1544
|
+
{ type: 'sapient-signer', address: extension.sessions, weight: 1n, imageHash },
|
|
1545
|
+
Hex.random(32),
|
|
1546
|
+
],
|
|
1547
|
+
},
|
|
1548
|
+
{ stateProvider },
|
|
1549
|
+
)
|
|
1550
|
+
const sessionManager = new Signers.SessionManager(wallet, {
|
|
1551
|
+
provider,
|
|
1552
|
+
sessionManagerAddress: extension.sessions,
|
|
1553
|
+
explicitSigners: [explicitSigner],
|
|
1554
|
+
})
|
|
1555
|
+
|
|
1556
|
+
const nonIncrementCall: Payload.Call = {
|
|
1557
|
+
to: EMITTER_ADDRESS1,
|
|
1558
|
+
value: 0n,
|
|
1559
|
+
data: AbiFunction.encodeData(EMITTER_FUNCTIONS[0]),
|
|
1560
|
+
gasLimit: 0n,
|
|
1561
|
+
delegateCall: false,
|
|
1562
|
+
onlyFallback: false,
|
|
1563
|
+
behaviorOnError: 'revert',
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
const fromNonIncrementOnly = await sessionManager.prepareIncrement(wallet.address, chainId, [
|
|
1567
|
+
nonIncrementCall,
|
|
1568
|
+
])
|
|
1569
|
+
expect(fromNonIncrementOnly).not.toBeNull()
|
|
1570
|
+
|
|
1571
|
+
// Pass [staleIncrement, nonIncrementCall] — increment is ignored when building; result should match
|
|
1572
|
+
const withStaleIncrement = await sessionManager.prepareIncrement(wallet.address, chainId, [
|
|
1573
|
+
fromNonIncrementOnly!,
|
|
1574
|
+
nonIncrementCall,
|
|
1575
|
+
])
|
|
1576
|
+
expect(withStaleIncrement).not.toBeNull()
|
|
1577
|
+
expect(withStaleIncrement!.data).toEqual(fromNonIncrementOnly!.data)
|
|
1578
|
+
},
|
|
1579
|
+
timeout,
|
|
1580
|
+
)
|
|
1581
|
+
|
|
1582
|
+
it(
|
|
1583
|
+
'payload with implicit and explicit: increment built only from explicit non-increment call',
|
|
1584
|
+
async () => {
|
|
1585
|
+
const provider = Provider.from(RpcTransport.fromHttp(LOCAL_RPC_URL))
|
|
1586
|
+
const chainId = Number(await provider.request({ method: 'eth_chainId' }))
|
|
1587
|
+
|
|
1588
|
+
const identityPrivateKey = Secp256k1.randomPrivateKey()
|
|
1589
|
+
const identityAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey: identityPrivateKey }))
|
|
1590
|
+
const stateProvider = new State.Local.Provider()
|
|
1591
|
+
|
|
1592
|
+
const redirectUrl = 'https://example.com'
|
|
1593
|
+
const implicitSigner = await createImplicitSigner(redirectUrl, identityPrivateKey)
|
|
1594
|
+
const sessionPermission: ExplicitSessionConfig = {
|
|
1595
|
+
chainId,
|
|
1596
|
+
valueLimit: 0n,
|
|
1597
|
+
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
1598
|
+
permissions: [PermissionBuilder.for(EMITTER_ADDRESS1).forFunction(EMITTER_FUNCTIONS[0]).onlyOnce().build()],
|
|
1599
|
+
}
|
|
1600
|
+
const explicitSigner = new Signers.Session.Explicit(Secp256k1.randomPrivateKey(), sessionPermission)
|
|
1601
|
+
|
|
1602
|
+
// Topology: identity + blacklist (implicit) + explicit session
|
|
1603
|
+
let sessionTopology = SessionConfig.emptySessionsTopology(identityAddress)
|
|
1604
|
+
sessionTopology = SessionConfig.addExplicitSession(sessionTopology, {
|
|
1605
|
+
...sessionPermission,
|
|
1606
|
+
signer: explicitSigner.address,
|
|
1607
|
+
})
|
|
1608
|
+
await stateProvider.saveTree(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
|
|
1609
|
+
const imageHash = GenericTree.hash(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
|
|
1610
|
+
|
|
1611
|
+
const wallet = await Wallet.fromConfiguration(
|
|
1612
|
+
{
|
|
1613
|
+
threshold: 1n,
|
|
1614
|
+
checkpoint: 0n,
|
|
1615
|
+
topology: [
|
|
1616
|
+
{ type: 'sapient-signer', address: extension.sessions, weight: 1n, imageHash },
|
|
1617
|
+
Hex.random(32),
|
|
1618
|
+
],
|
|
1619
|
+
},
|
|
1620
|
+
{ stateProvider },
|
|
1621
|
+
)
|
|
1622
|
+
const sessionManager = new Signers.SessionManager(wallet, {
|
|
1623
|
+
provider,
|
|
1624
|
+
sessionManagerAddress: extension.sessions,
|
|
1625
|
+
implicitSigners: [implicitSigner],
|
|
1626
|
+
explicitSigners: [explicitSigner],
|
|
1627
|
+
})
|
|
1628
|
+
|
|
1629
|
+
// Explicit call only (onlyOnce produces an increment; implicit does not match this target)
|
|
1630
|
+
const call: Payload.Call = {
|
|
1631
|
+
to: EMITTER_ADDRESS1,
|
|
1632
|
+
value: 0n,
|
|
1633
|
+
data: AbiFunction.encodeData(EMITTER_FUNCTIONS[0]),
|
|
1634
|
+
gasLimit: 0n,
|
|
1635
|
+
delegateCall: false,
|
|
1636
|
+
onlyFallback: false,
|
|
1637
|
+
behaviorOnError: 'revert',
|
|
1638
|
+
}
|
|
1639
|
+
const increment = await sessionManager.prepareIncrement(wallet.address, chainId, [call])
|
|
1640
|
+
expect(increment).not.toBeNull()
|
|
1641
|
+
const calls = includeIncrement([call], increment!, extension.sessions)
|
|
1642
|
+
const transaction = await buildAndSignCall(wallet, sessionManager, calls, provider, chainId)
|
|
1643
|
+
await simulateTransaction(provider, transaction, EMITTER_EVENT_TOPICS[0])
|
|
1644
|
+
},
|
|
1645
|
+
timeout,
|
|
1646
|
+
)
|
|
1647
|
+
|
|
1648
|
+
it('signSapient handles selector-only self increment call consistently', async () => {
|
|
1649
|
+
const identityPrivateKey = Secp256k1.randomPrivateKey()
|
|
1650
|
+
const identityAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey: identityPrivateKey }))
|
|
1651
|
+
const stateProvider = new State.Local.Provider()
|
|
1652
|
+
|
|
1653
|
+
const explicitSigner = new Signers.Session.Explicit(Secp256k1.randomPrivateKey(), {
|
|
1654
|
+
chainId: 0,
|
|
1655
|
+
valueLimit: 0n,
|
|
1656
|
+
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
1657
|
+
permissions: [PermissionBuilder.for(EMITTER_ADDRESS1).allowAll().build()],
|
|
1658
|
+
})
|
|
1659
|
+
|
|
1660
|
+
const sessionTopology = SessionConfig.addExplicitSession(SessionConfig.emptySessionsTopology(identityAddress), {
|
|
1661
|
+
...explicitSigner.sessionPermissions,
|
|
1662
|
+
signer: explicitSigner.address,
|
|
1663
|
+
})
|
|
1664
|
+
await stateProvider.saveTree(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
|
|
1665
|
+
const imageHash = GenericTree.hash(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
|
|
1666
|
+
|
|
1667
|
+
const wallet = await Wallet.fromConfiguration(
|
|
1668
|
+
{
|
|
1669
|
+
threshold: 1n,
|
|
1670
|
+
checkpoint: 0n,
|
|
1671
|
+
topology: [{ type: 'sapient-signer', address: extension.sessions, weight: 1n, imageHash }, Hex.random(32)],
|
|
1672
|
+
},
|
|
1673
|
+
{ stateProvider },
|
|
1674
|
+
)
|
|
1675
|
+
const sessionManager = new Signers.SessionManager(wallet, {
|
|
1676
|
+
sessionManagerAddress: extension.sessions,
|
|
1677
|
+
explicitSigners: [explicitSigner],
|
|
1678
|
+
})
|
|
1679
|
+
|
|
1680
|
+
const payload: Payload.Parented = {
|
|
1681
|
+
type: 'call',
|
|
1682
|
+
nonce: 0n,
|
|
1683
|
+
space: 0n,
|
|
1684
|
+
calls: [
|
|
1685
|
+
{
|
|
1686
|
+
to: extension.sessions,
|
|
1687
|
+
data: AbiFunction.getSelector(Constants.INCREMENT_USAGE_LIMIT),
|
|
1688
|
+
value: 0n,
|
|
1689
|
+
gasLimit: 0n,
|
|
1690
|
+
delegateCall: false,
|
|
1691
|
+
onlyFallback: false,
|
|
1692
|
+
behaviorOnError: 'revert',
|
|
1693
|
+
},
|
|
1694
|
+
],
|
|
1695
|
+
parentWallets: [wallet.address],
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
const signature = await sessionManager.signSapient(wallet.address, 0, payload, imageHash)
|
|
1699
|
+
expect(signature.type).toBe('sapient')
|
|
1700
|
+
})
|
|
1701
|
+
})
|
|
1360
1702
|
})
|
|
1361
1703
|
}
|
package/test/signers-pk.test.ts
CHANGED
|
@@ -143,7 +143,7 @@ describe('Private Key Signers', () => {
|
|
|
143
143
|
await pk.witness(mockStateWriter, testWallet)
|
|
144
144
|
|
|
145
145
|
expect(mockStateWriter.saveWitnesses).toHaveBeenCalledTimes(1)
|
|
146
|
-
const [wallet, chainId,
|
|
146
|
+
const [wallet, chainId, _payload, witness] = vi.mocked(mockStateWriter.saveWitnesses).mock.calls[0]
|
|
147
147
|
|
|
148
148
|
expect(wallet).toBe(testWallet)
|
|
149
149
|
expect(chainId).toBe(0)
|
|
@@ -236,7 +236,6 @@ describe('Implicit Session', () => {
|
|
|
236
236
|
},
|
|
237
237
|
}
|
|
238
238
|
const identitySignature = createValidIdentitySignature(attestation)
|
|
239
|
-
const topology = createValidTopology()
|
|
240
239
|
|
|
241
240
|
// This should throw an error during construction due to future issued time
|
|
242
241
|
expect(() => {
|
|
@@ -250,7 +249,6 @@ describe('Implicit Session', () => {
|
|
|
250
249
|
approvedSigner: randomAddress(), // Different approved signer
|
|
251
250
|
}
|
|
252
251
|
const identitySignature = createValidIdentitySignature(attestation)
|
|
253
|
-
const topology = createValidTopology()
|
|
254
252
|
|
|
255
253
|
// This should throw an error during construction due to mismatched approved signer
|
|
256
254
|
expect(() => {
|
package/test/state/debug.test.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { multiplex } from '../../src/state/debug.js'
|
|
|
5
5
|
|
|
6
6
|
// Test data
|
|
7
7
|
const TEST_ADDRESS = Address.from('0x1234567890123456789012345678901234567890')
|
|
8
|
-
const TEST_HEX = Hex.from('0xabcdef123456')
|
|
9
8
|
const TEST_UINT8ARRAY = new Uint8Array([171, 205, 239, 18, 52, 86])
|
|
10
9
|
|
|
11
10
|
describe('State Debug', () => {
|
|
@@ -241,13 +240,13 @@ describe('State Debug', () => {
|
|
|
241
240
|
}
|
|
242
241
|
|
|
243
242
|
const complexRef: ComplexInterface = {
|
|
244
|
-
async complexMethod(
|
|
243
|
+
async complexMethod() {
|
|
245
244
|
return 'complex-ref'
|
|
246
245
|
},
|
|
247
246
|
}
|
|
248
247
|
|
|
249
248
|
const complexCand: ComplexInterface = {
|
|
250
|
-
async complexMethod(
|
|
249
|
+
async complexMethod() {
|
|
251
250
|
return 'complex-cand'
|
|
252
251
|
},
|
|
253
252
|
}
|