Generate signers

Generate signers

User signatures are required for certain types of operations on XpansionChain. These are:

  1. Transactions that update blockchain state

  2. Operations that update XpansionChain's databases that require user authorization for

Examples:

✅ Require user signatures
❌ Do not require user signatures

Transactions that update blockchain state

Operations requiring user authorization

Read-only operations

  • Creating an order

  • Filling an order (creating a trade)

  • Transferring assets between users

  • Depositing assets on L2 (XpansionChain)

  • Withdrawing assets to L1 (Layer 1 Ethereum)

  • Creating a project

  • Registering a user off-chain

  • Getting a list of all assets on XpansionChain

  • Getting the details (ie. metadata) of a particular asset

  • Getting a list of all open orders

  • Getting a list of historical trades

Using "signers" to get user signatures

In order to get user signatures, applications can use "signers". These are abstractions of user accounts that can be used to sign transactions. A user's private key is required to generate them.

Ethereum (L1) signers are required to sign transactions on L1 (ie. depositing assets from the L1 wallet to the L2 one) and Stark (L2) signers are required to sign transactions on L2 (ie. creating an order on an L2 marketplace, transferring an asset to another user on L2).

How do applications generate and use signers?

There are two ways to get signers in your application:

  1. Generate your own by obtaining and using the user's private keys

  2. Connect to a user's wallet application

The first option, where an application obtains a user's private key directly, is risky because these keys allow anyone in possession of them full control of an account.

The second option provides an application with an interface to the user's account by prompting the user to connect with their wallet application (ie. mobile or browser wallet). Once connected the app can begin asking the user to sign transactions and messages without having to reveal their private key.

1. Generate your own signers

💡AVAILABLE WITH:

  • Core SDK

Core SDK

Below are instructions on how to generate:

  • Ethereum (L1) signers

  • Stark (L2) private keys and signers using the Core SDK

CAUTION

If you generate your own Stark private key, you will have to persist it. The key is randomly generated so cannot be deterministically re-generated.

  • Typescript Core SDK

The Core SDK provides functionality for applications to generate Stark (L2) private keys and signers:

  • Kotlin (JVM) Core SDK

In order to use any workflow functions, you will need to pass in the connected wallet provider. This means you will need to implement your own Wallet L1 Signer.

Once you have created a Signer instance you can generate the user's Stark key pair and use it to create an instance of StandardStarkSigner, an implementation of StarkSigner.

  • Swift Core SDK

In order to use any workflow functions, you will need to pass in the connected wallet provider. This means you will need to implement your own Wallet L1 Signer and L2 StarkSigner.

Once you have a Signer instance you can generate the user's Stark key pair and use the result to instantiate a StarkSigner, for example, by using the default StandardStarkSigner provided by the SDK.

  • Golang Core SDK

1. Generate L1 signer

When you implement an L1signer, it must satisfy L1Signer interface. See BaseL1Signer for a sample implementation of an L1 Signer.

Also refer to examples/publicapi/list_assets/main.go for environment setup examples.

2. Generate L2 signer

See signers/stark for information about generating your own L2 signer, as well as the following code snippet:

2. Connect to users' wallets

Your application can facilitate signing of user transactions by connecting to users' wallet applications. This ensures that you do not have to handle private keys.

💡AVAILABLE WITH:

  • Wallet SDK (with Core SDK)

  • Link SDK

  • Wallet SDK

The Wallet SDK provides a way for applications to connect to certain user wallets:

Wallet SDK
Platform
Wallets supported

Wallet SDK Web

Web

  • Metamask

  • WalletConnect

Wallet SDK Android

Android

  • Any wallet that supports WalletConnect v1.0

Wallet SDK iOS

iOS

  • Any wallet that supports WalletConnect v1.0

  • Wallet SDK Web

  1. Install the Wallet SDK npm package:

  1. Set up the Wallet SDK and use with the Core SDK for Typescript:

TIP

The WalletConnection object can also be retrieved in the following ways:

  • Wallet SDK Android

  1. Add Maven Central and JitPack to your repositories

  1. Add the dependency to your app's build.gradle file:

  1. In your Application class:

  1. Connect to the user's wallet

If you want to use your own bridge server instead of the default provide it via bridgeServerUrl when connecting. For more info on how WalletConnect and the bridge works see here.

  1. Use with the Core SDK for Kotlin/JVM

Once you connect a user's wallet with the Wallet SDK you can provide the Signer and StarkSigner instances to Core SDK workflows:

  • Wallet SDK iOS

  1. Add pod XpansionChainXWallet to your Podfile

  1. Connect to the user's wallet

If you want to use your own bridge server instead of the default provide it via bridgeServerUrl when connecting. For more info on how WalletConnect and the bridge works see here.

  1. Use with the Core SDK for Swift

Once you connect a user's wallet with the Wallet SDK you can provide the Signer and StarkSigner instances to Core SDK workflows:

  • Link SDK

  1. Install the npm package:

  1. Import the Link package:

  1. Set the correct network URL

Choose from the following:

Network
Description
URL

Sandbox

The default test network (currently, it is Goërli)

https://link.sandbox.x.XpansionChain.com/v1

Production

Ethereum network

https://link.x.XpansionChain.com/v1

  1. Initialize the client

Operations like registering a user (see guide) can be executed by the Link client, which uses the JS SDK under the hood.

Last updated