makahiki
v1.0.0
Published
The smart account SDK for Stackup's onchain financial platform.
Downloads
258
Readme
makahiki.js
The smart account SDK for Stackup's onchain financial platform.
Getting started
This library enables interactions with a smart account composed of the following components:
- Kernel for the core ERC-7579 account.
- Smart Sessions for granular permissions.
- Account Modules for miscellaneous authentication and authorization modules.
The package itself builds on top of viem's account abstraction interface.
Installation
Note: this SDK uses a [email protected] and [email protected]. It is recommended to pin these versions to avoid typing issues.
pnpm install makahiki
Initialize smart account
import { http, pad } from "viem";
import { sepolia } from "viem/chains";
import { toSmartAccount } from "makahiki";
const account = await toSmartAccount({
rootPublicKey,
signerPublicKey,
webAuthnAccount,
publicClientConfig: {
chain: sepolia,
transport: http("Your node rpc here..."),
},
// Optional fields
salt: pad("0x00", { size: 32 }),
nonceKey: 0n,
});
Initialization options
| Option | Description |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| rootPublicKey | A hex public key of the root admin that deployed the smart account. Equivalent to viem's webAuthnAccount.publicKey
. This determines the counterfactual address. |
| signerPublicKey | A hex public key of the current signer for outgoing transactions. Equivalent to viem's webAuthnAccount.publicKey
. |
| webAuthnAccount | The webAuthn interface for the current user. See here. |
| publicClientConfig | The same config object to initialize a viem Public Client. Note that chain
is required. See here. |
| salt | A 32 byte hex string that is used to derive the smart account address. Defaults to the zero hash. (Optional) |
| nonceKey | A bigint value to set the key for the 2D nonce. Defaults to 0. (Optional) |
Return type
Returns an instance of a viem SmartAccount
.
Encoding sessions
Access controls are built on top of the Smart Sessions module. We also export a collection of helper functions to work with sessions built for the Stackup use case.
WebAuthnSession
These are sessions tied to a WebAuthn passkey. Below are code examples for adding and removing pre defined sessions.
import { encodeFunctionData } from "viem";
import {
SmartSession,
WebAuthnSession,
IntervalSpendingLimitPolicy,
} from "makahiki";
// Encode a function call to enable a sudo session.
const sudoCallData = encodeFunctionData({
abi: SmartSession.abi,
functionName: "enableSessions",
args: [[WebAuthnSession.initSudoSession(p256Credentials.publicKey)]],
});
// Encode a function call to enable a limited spender session.
const spenderCallData = encodeFunctionData({
abi: SmartSession.abi,
functionName: "enableSessions",
args: [
[
WebAuthnSession.initLimitedSpenderSession(p256Credentials.publicKey, {
token, // Address, for ETH use IntervalSpendingLimitPolicy.NATIVE_TOKEN_FLAG
value, // bigint
interval, // "Daily" | "Weekly" | "Monthly"
}),
],
],
});
// Encode a function call to remove a signer's session.
const removeCallData = encodeFunctionData({
abi: SmartSession.abi,
functionName: "removeSession",
args: [WebAuthnSession.getPermissionId(p256Credentials.publicKey)],
});
There are also several additional utility functions for encoding ids and signatures.
// Get a permissionId for a given passkey.
const pid = WebAuthnSession.getPermissionId(p256Credentials.publicKey);
// Encode a session signature for a UserOperation.
const sig = WebAuthnSession.encodeSignature(p256Credentials.publicKey, {
authenticatorData,
clientDataJSONPre,
clientDataJSONPost,
challengeIndex: BigInt(challengeIndex),
typeIndex: BigInt(typeIndex),
r,
s,
});
SessionUtils
Generic utility functions for working with Stackup + Smart Sessions is also available under the SessionUtils
namespace.
import { SessionUtils } from "makahiki";
For a full list of available function see session/utils.ts
.
Contributing
Steps for setting up a local dev environment for contributing to makahiki.js.
Prerequisites
- Node >=18.0.0
Setup
Install dependencies:
pnpm install
Run tests:
pnpm test
License
Distributed under the MIT License. See LICENSE for more information.