Skip to content

Commit 35d95fa

Browse files
authored
Merge pull request #38 from argentlabs/develop
Release v7.0.0
2 parents e5c034b + 01b36c7 commit 35d95fa

20 files changed

+1463
-1077
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- develop
77
- main
8+
- beta
89
- hotfix\/v[0-9]+.[0-9]+.[0-9]+
910

1011
jobs:

README.md

Lines changed: 113 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ A demo dapp using both sessions and offchain sessions can be found here [https:/
2222

2323
First you need to have a deployed account. This is the account that will authorise the session and interact with the contracts of your dapp.
2424

25-
To sign the session message the method needed is `openSession`. After the user sign the message, a session account can be created using `buildSessionAccount`.
25+
To sign the session message the method needed is `createSession`. After the user sign the message, a session account can be created using `buildSessionAccount`.
2626

2727
This example session will allow the dapp to execute an example endpoint on an example contract without asking the user to approve the transaction again. After signing the session the dapp can execute all transactions listed in `allowedMethods` whenever it wants and as many times as it wants.
2828

@@ -45,8 +45,8 @@ export type SessionMetadata = {
4545
projectSignature?: Signature
4646
}
4747

48-
type SessionParams = {
49-
dappKey?: Uint8Array // this is optional. This sdk generate a dappKey using ec.starkCurve.utils.randomPrivateKey() if not provided
48+
type CreateSessionParams = {
49+
sessionKey?: Uint8Array // this is optional. This sdk generate a sessionKey using ec.starkCurve.utils.randomPrivateKey() if not provided
5050
allowedMethods: AllowedMethod[]
5151
expiry: bigint
5252
metaData: SessionMetadata
@@ -58,13 +58,22 @@ The following snippet show how to create and use a session account
5858
```typescript
5959
import {
6060
SignSessionError,
61-
SessionParams,
62-
openSession,
63-
buildSessionAccount
61+
CreateSessionParams,
62+
createSession,
63+
buildSessionAccount,
64+
bytesToHexString
6465
} from "@argent/x-sessions"
6566
import { ec } from "starknet"
6667

67-
const sessionParams: SessionParams = {
68+
const privateKey = ec.starkCurve.utils.randomPrivateKey()
69+
70+
const sessionKey: SessionKey = {
71+
privateKey: bytesToHexString(privateKey),
72+
publicKey: ec.starkCurve.getStarkKey(privateKey)
73+
}
74+
75+
const sessionParams: CreateSessionParams = {
76+
sessionKey,
6877
allowedMethods: [
6978
{
7079
"Contract Address": contractAddress,
@@ -74,7 +83,7 @@ const sessionParams: SessionParams = {
7483
expiry: Math.floor(
7584
(Date.now() + 1000 * 60 * 60 * 24) / 1000
7685
) as any, // ie: 1 day
77-
dappKey: ec.starkCurve.utils.randomPrivateKey(),
86+
sessionKey: ec.starkCurve.utils.randomPrivateKey(),
7887
metaData: {
7988
projectID: "test-dapp",
8089
txFees: [
@@ -86,34 +95,35 @@ const sessionParams: SessionParams = {
8695
}
8796
}
8897

89-
// open session and sign message
90-
const accountSessionSignature = await openSession({
91-
wallet, // StarknetWindowObject
92-
sessionParams, // SessionParams
93-
chainId // StarknetChainId
98+
// create the session request to get the typed data to be signed
99+
const sessionRequest = createSessionRequest({
100+
sessionParams,
101+
chainId
94102
})
95103

96-
// create the session account from the current one that will be used to submit transactions
97-
const sessionRequest = createSessionRequest(
98-
sessionParams.allowedMethods,
99-
sessionParams.expiry,
100-
sessionParams.metaData,
101-
sessionParams.dappKey
102-
)
104+
// wallet is a StarknetWindowObject
105+
const authorisationSignature = await wallet.request({
106+
type: "wallet_signTypedData",
107+
params: sessionRequest.sessionTypedData
108+
})
109+
110+
// open session and sign message
111+
const session = await createSession({
112+
sessionRequest, // SessionRequest
113+
address, // Account address
114+
chainId, // StarknetChainId
115+
authorisationSignature // Signature
116+
})
103117

104118
const sessionAccount = await buildSessionAccount({
105119
useCacheAuthorisation: false, // optional and defaulted to false, will be added in future developments
106-
accountSessionSignature: stark.formatSignature(
107-
accountSessionSignature
108-
),
109-
sessionRequest,
110-
chainId, // StarknetChainId
120+
session,
121+
sessionKey,
111122
provider: new RpcProvider({
112123
nodeUrl: "https://starknet-sepolia.public.blastapi.io/rpc/v0_7",
113124
chainId: constants.StarknetChainId.SN_SEPOLIA
114125
}),
115-
address, // account address
116-
dappKey
126+
argentSessionServiceBaseUrl: ARGENT_SESSION_SERVICE_BASE_URL // Optional: defaulted to mainnet url
117127
})
118128

119129
try {
@@ -138,24 +148,72 @@ Executing transactions “from outside” allows an account to submit transactio
138148
This package expose a method in order to get the Call required to perform an execution from outside.
139149

140150
```typescript
141-
// instantiate argent session service
142-
const beService = new ArgentSessionService(
143-
dappKey.publicKey,
144-
accountSessionSignature
145-
)
151+
const privateKey = ec.starkCurve.utils.randomPrivateKey()
146152

147-
// instantiate dapp session service
148-
const sessionDappService = new SessionDappService(
149-
beService,
150-
chainId,
151-
dappKey
152-
)
153+
const sessionKey: SessionKey = {
154+
privateKey: bytesToHexString(privateKey),
155+
publicKey: ec.starkCurve.getStarkKey(privateKey)
156+
}
157+
158+
const sessionParams: CreateSessionParams = {
159+
sessionKey,
160+
allowedMethods: [
161+
{
162+
"Contract Address": contractAddress,
163+
selector: "method_selector"
164+
}
165+
],
166+
expiry: Math.floor(
167+
(Date.now() + 1000 * 60 * 60 * 24) / 1000
168+
) as any, // ie: 1 day
169+
sessionKey: ec.starkCurve.utils.randomPrivateKey(),
170+
metaData: {
171+
projectID: "test-dapp",
172+
txFees: [
173+
{
174+
tokenAddress: ETHTokenAddress,
175+
maxAmount: parseUnits("0.1", 18).value.toString()
176+
}
177+
]
178+
}
179+
}
180+
181+
// create the session request to get the typed data to be signed
182+
const sessionRequest = createSessionRequest({
183+
sessionParams,
184+
chainId
185+
})
186+
187+
// wallet is a StarknetWindowObject
188+
const authorisationSignature = await wallet.request({
189+
type: "wallet_signTypedData",
190+
params: sessionRequest.sessionTypedData
191+
})
192+
193+
// open session and sign message
194+
const session = await createSession({
195+
sessionRequest, // SessionRequest
196+
address, // Account address
197+
chainId, // StarknetChainId
198+
authorisationSignature // Signature
199+
})
200+
201+
const sessionAccount = await buildSessionAccount({
202+
useCacheAuthorisation: false, // optional and defaulted to false, will be added in future developments
203+
session,
204+
sessionKey,
205+
provider: new RpcProvider({
206+
nodeUrl: "https://starknet-sepolia.public.blastapi.io/rpc/v0_7",
207+
chainId: constants.StarknetChainId.SN_SEPOLIA
208+
}),
209+
argentSessionServiceBaseUrl: ARGENT_SESSION_SERVICE_BASE_URL // Optional: defaulted to mainnet url
210+
})
153211

154212
// example for creating the calldata
155213
const erc20Contract = new Contract(
156214
Erc20Abi as Abi,
157215
ETHTokenAddress,
158-
sessionAccount as any
216+
sessionAccount
159217
)
160218
const calldata = erc20Contract.populate("transfer", {
161219
recipient: address,
@@ -164,18 +222,20 @@ const calldata = erc20Contract.populate("transfer", {
164222

165223
// get execute from outside data
166224
const { contractAddress, entrypoint, calldata } =
167-
await sessionDappService.getOutsideExecutionCall(
168-
sessionRequest,
169-
stark.formatSignature(accountSessionSignature),
170-
false,
171-
[calldata],
172-
address, // the account address
173-
chainId,
174-
shortString.encodeShortString("ANY_CALLER"), // Optional: default value ANY_CALLER
175-
execute_after, // Optional: timestamp in seconds - this is the lower value in the range. Default value: 5 mins before Date.now()
176-
execute_before, // Optional: timestamp in seconds - this is the upper value in the range. Default value: 20 mins after Date.now()
177-
nonce: BigNumberish, // Optional: nonce, default value is a random nonce
178-
)
179-
```
225+
await createOutsideExecutionCall({
226+
session,
227+
sessionKey,
228+
calls: [transferCallData],
229+
argentSessionServiceUrl: ARGENT_SESSION_SERVICE_BASE_URL
230+
network // values "mainnet" | "sepolia", default to "mainnet"
231+
})
180232

181-
Another account can then use object `{ contractAddress, entrypoint, calldata }` to execute the transaction.
233+
const { signature, outsideExecutionTypedData } =
234+
await createOutsideExecutionTypedData({
235+
session,
236+
sessionKey,
237+
calls: [transferCallData],
238+
argentSessionServiceUrl: ARGENT_SESSION_SERVICE_BASE_URL
239+
network // values "mainnet" | "sepolia", default to "mainnet"
240+
})
241+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@argent/x-sessions",
3-
"version": "6.7.10",
3+
"version": "7.0.0",
44
"private": false,
55
"description": "Manage sessions for Argent X wallets",
66
"keywords": [

0 commit comments

Comments
 (0)