@ab-org/sdk-core 0.1.0 → 0.1.2-beta.0
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/README.md +29 -0
- package/dist/chunk-5HURLKIK.js +1005 -0
- package/dist/chunk-MVZIAM4H.js +363 -0
- package/dist/cubeSignerAuth-DrPc9FeB.d.ts +426 -0
- package/dist/index.d.ts +237 -16
- package/dist/index.js +1119 -16
- package/dist/social-auth.d.ts +11 -0
- package/dist/social-auth.js +1 -0
- package/dist/social-provider-Bq58TBRt.d.ts +88 -0
- package/dist/social-provider.d.ts +2 -0
- package/dist/social-provider.js +2 -0
- package/dist/social.d.ts +3 -0
- package/dist/social.js +2 -0
- package/package.json +24 -6
- package/dist/core/capabilities.d.ts +0 -32
- package/dist/core/capabilities.js +0 -88
- package/dist/core/chains.d.ts +0 -23
- package/dist/core/chains.js +0 -83
- package/dist/core/errors.d.ts +0 -9
- package/dist/core/errors.js +0 -51
- package/dist/core/sessionStore.d.ts +0 -26
- package/dist/core/sessionStore.js +0 -129
- package/dist/core/types.d.ts +0 -75
- package/dist/core/types.js +0 -1
- package/dist/core/walletConnector.d.ts +0 -29
- package/dist/core/walletConnector.js +0 -153
- package/dist/core/walletExecution.d.ts +0 -22
- package/dist/core/walletExecution.js +0 -89
- package/dist/hooks/useAccount.d.ts +0 -11
- package/dist/hooks/useAccount.js +0 -32
- package/dist/hooks/useWalletConnect.d.ts +0 -16
- package/dist/hooks/useWalletConnect.js +0 -24
- package/dist/providers/base.d.ts +0 -15
- package/dist/providers/base.js +0 -30
- package/dist/providers/plugin/injectedEvmProvider.d.ts +0 -112
- package/dist/providers/plugin/injectedEvmProvider.js +0 -352
- package/dist/providers/plugin/injectedWalletRegistry.d.ts +0 -9
- package/dist/providers/plugin/injectedWalletRegistry.js +0 -34
- package/dist/providers/plugin/metamaskProvider.d.ts +0 -1
- package/dist/providers/plugin/metamaskProvider.js +0 -1
- package/dist/providers/social/baseSocialProvider.d.ts +0 -21
- package/dist/providers/social/baseSocialProvider.js +0 -11
- package/dist/providers/social/cubeSignerAuth.d.ts +0 -89
- package/dist/providers/social/cubeSignerAuth.js +0 -128
- package/dist/providers/social/cubistEvmWalletProvider.d.ts +0 -9
- package/dist/providers/social/cubistEvmWalletProvider.js +0 -175
- package/dist/providers/social/cubistProvider.d.ts +0 -52
- package/dist/providers/social/cubistProvider.js +0 -160
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { EvmSigner } from "@cubist-labs/cubesigner-sdk";
|
|
2
|
-
const evmChainIdMap = {
|
|
3
|
-
ETH: 1,
|
|
4
|
-
BSC: 56,
|
|
5
|
-
};
|
|
6
|
-
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
-
const toBigIntQuantity = (value) => {
|
|
8
|
-
if (typeof value === "bigint")
|
|
9
|
-
return value;
|
|
10
|
-
if (typeof value === "number") {
|
|
11
|
-
if (!Number.isInteger(value) || value < 0) {
|
|
12
|
-
throw new Error(`Invalid EVM quantity number: ${value}`);
|
|
13
|
-
}
|
|
14
|
-
return BigInt(value);
|
|
15
|
-
}
|
|
16
|
-
const trimmed = value.trim();
|
|
17
|
-
if (!trimmed) {
|
|
18
|
-
throw new Error("EVM quantity cannot be empty");
|
|
19
|
-
}
|
|
20
|
-
if (/^0x[0-9a-fA-F]+$/.test(trimmed) || /^\d+$/.test(trimmed)) {
|
|
21
|
-
return BigInt(trimmed);
|
|
22
|
-
}
|
|
23
|
-
throw new Error(`Invalid EVM quantity string: ${value}`);
|
|
24
|
-
};
|
|
25
|
-
const toHexQuantity = (value) => {
|
|
26
|
-
if (value === undefined)
|
|
27
|
-
return undefined;
|
|
28
|
-
return `0x${toBigIntQuantity(value).toString(16)}`;
|
|
29
|
-
};
|
|
30
|
-
const normalizeAccessList = (accessList) => {
|
|
31
|
-
if (!accessList)
|
|
32
|
-
return undefined;
|
|
33
|
-
return accessList.map((item) => ({
|
|
34
|
-
address: item.address,
|
|
35
|
-
storageKeys: item.storageKeys,
|
|
36
|
-
}));
|
|
37
|
-
};
|
|
38
|
-
const textEncoder = new TextEncoder();
|
|
39
|
-
const resolveTransactionType = (transaction) => {
|
|
40
|
-
if (transaction.type !== undefined) {
|
|
41
|
-
const normalized = toHexQuantity(transaction.type);
|
|
42
|
-
if (normalized === "0x0" || normalized === "0x1" || normalized === "0x2") {
|
|
43
|
-
return normalized;
|
|
44
|
-
}
|
|
45
|
-
throw new Error(`Unsupported EVM transaction type for Cubist: ${normalized}`);
|
|
46
|
-
}
|
|
47
|
-
if (transaction.maxFeePerGas !== undefined || transaction.maxPriorityFeePerGas !== undefined) {
|
|
48
|
-
return "0x2";
|
|
49
|
-
}
|
|
50
|
-
if (transaction.accessList?.length) {
|
|
51
|
-
return "0x1";
|
|
52
|
-
}
|
|
53
|
-
return "0x0";
|
|
54
|
-
};
|
|
55
|
-
const toCubistSignRequest = (address, chain, transaction) => {
|
|
56
|
-
const resolvedChainId = (transaction.chainId !== undefined ? Number(toBigIntQuantity(transaction.chainId)) : undefined) ??
|
|
57
|
-
evmChainIdMap[chain];
|
|
58
|
-
if (!resolvedChainId) {
|
|
59
|
-
throw new Error("Cubist signing requires an EVM chainId");
|
|
60
|
-
}
|
|
61
|
-
const type = resolveTransactionType(transaction);
|
|
62
|
-
const commonFields = {
|
|
63
|
-
from: transaction.from ?? address,
|
|
64
|
-
to: transaction.to,
|
|
65
|
-
data: transaction.data,
|
|
66
|
-
gas: toHexQuantity(transaction.gas),
|
|
67
|
-
nonce: toHexQuantity(transaction.nonce),
|
|
68
|
-
value: toHexQuantity(transaction.value),
|
|
69
|
-
};
|
|
70
|
-
const accessList = normalizeAccessList(transaction.accessList);
|
|
71
|
-
const tx = type === "0x2"
|
|
72
|
-
? {
|
|
73
|
-
...commonFields,
|
|
74
|
-
type,
|
|
75
|
-
...(accessList ? { accessList } : {}),
|
|
76
|
-
maxFeePerGas: toHexQuantity(transaction.maxFeePerGas),
|
|
77
|
-
maxPriorityFeePerGas: toHexQuantity(transaction.maxPriorityFeePerGas),
|
|
78
|
-
}
|
|
79
|
-
: type === "0x1"
|
|
80
|
-
? {
|
|
81
|
-
...commonFields,
|
|
82
|
-
type,
|
|
83
|
-
...(accessList ? { accessList } : {}),
|
|
84
|
-
gasPrice: toHexQuantity(transaction.gasPrice),
|
|
85
|
-
}
|
|
86
|
-
: {
|
|
87
|
-
...commonFields,
|
|
88
|
-
type,
|
|
89
|
-
gasPrice: toHexQuantity(transaction.gasPrice),
|
|
90
|
-
};
|
|
91
|
-
return {
|
|
92
|
-
chain_id: resolvedChainId,
|
|
93
|
-
tx,
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
const getTransactionParam = (params) => {
|
|
97
|
-
const candidate = params?.[0];
|
|
98
|
-
if (!isRecord(candidate)) {
|
|
99
|
-
throw new Error("eth_signTransaction requires a transaction object");
|
|
100
|
-
}
|
|
101
|
-
return candidate;
|
|
102
|
-
};
|
|
103
|
-
const toHexBytes = (value) => {
|
|
104
|
-
if (/^0x[0-9a-fA-F]*$/.test(value))
|
|
105
|
-
return value;
|
|
106
|
-
return `0x${Array.from(textEncoder.encode(value))
|
|
107
|
-
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
108
|
-
.join("")}`;
|
|
109
|
-
};
|
|
110
|
-
const getMessageParam = (address, params) => {
|
|
111
|
-
const [first, second] = params ?? [];
|
|
112
|
-
if (typeof second === "string" && second.toLowerCase() === address.toLowerCase()) {
|
|
113
|
-
return String(first ?? "");
|
|
114
|
-
}
|
|
115
|
-
if (typeof first === "string" && first.toLowerCase() === address.toLowerCase()) {
|
|
116
|
-
return String(second ?? "");
|
|
117
|
-
}
|
|
118
|
-
return String(first ?? "");
|
|
119
|
-
};
|
|
120
|
-
const getTypedDataParam = (address, params) => {
|
|
121
|
-
const [first, second] = params ?? [];
|
|
122
|
-
if (typeof first === "string" && first.toLowerCase() === address.toLowerCase()) {
|
|
123
|
-
return typeof second === "string" ? JSON.parse(second) : (second ?? {});
|
|
124
|
-
}
|
|
125
|
-
return typeof second === "string" ? JSON.parse(second) : (second ?? first ?? {});
|
|
126
|
-
};
|
|
127
|
-
export const createCubistEvmWalletProvider = ({ session, address, chain, }) => {
|
|
128
|
-
const signer = new EvmSigner(address, session.client);
|
|
129
|
-
return {
|
|
130
|
-
async request(payload) {
|
|
131
|
-
switch (payload.method) {
|
|
132
|
-
case "eth_accounts":
|
|
133
|
-
case "eth_requestAccounts":
|
|
134
|
-
return [address];
|
|
135
|
-
case "eth_chainId": {
|
|
136
|
-
const chainId = evmChainIdMap[chain];
|
|
137
|
-
if (!chainId) {
|
|
138
|
-
throw new Error(`CubistProvider: chain ${chain} does not expose an EVM chainId`);
|
|
139
|
-
}
|
|
140
|
-
return `0x${chainId.toString(16)}`;
|
|
141
|
-
}
|
|
142
|
-
case "eth_signTransaction": {
|
|
143
|
-
const transaction = getTransactionParam(payload.params);
|
|
144
|
-
const signRequest = toCubistSignRequest(address, chain, transaction);
|
|
145
|
-
return (await signer.signTransaction(signRequest));
|
|
146
|
-
}
|
|
147
|
-
case "personal_sign": {
|
|
148
|
-
const message = getMessageParam(address, payload.params);
|
|
149
|
-
return (await signer.signEip191({
|
|
150
|
-
data: toHexBytes(message),
|
|
151
|
-
}));
|
|
152
|
-
}
|
|
153
|
-
case "eth_signTypedData_v4": {
|
|
154
|
-
const typedData = getTypedDataParam(address, payload.params);
|
|
155
|
-
const domain = typedData.domain;
|
|
156
|
-
const chainId = domain?.chainId !== undefined
|
|
157
|
-
? Number(toBigIntQuantity(domain.chainId))
|
|
158
|
-
: evmChainIdMap[chain];
|
|
159
|
-
if (!chainId) {
|
|
160
|
-
throw new Error("CubistProvider: typed data signing requires an EVM chainId");
|
|
161
|
-
}
|
|
162
|
-
return (await signer.signEip712({
|
|
163
|
-
chain_id: chainId,
|
|
164
|
-
typed_data: typedData,
|
|
165
|
-
}));
|
|
166
|
-
}
|
|
167
|
-
default:
|
|
168
|
-
throw new Error(`CubistProvider: unsupported RPC method "${payload.method}"`);
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
async disconnect() {
|
|
172
|
-
await session.client.revokeSession();
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { AbstractSocialProvider, type SocialLoginOptions } from "./baseSocialProvider.js";
|
|
2
|
-
import type { WalletConnectArgs, WalletSession } from "../../core/types.js";
|
|
3
|
-
import { CubeSignerAuth, type CubeSignerConfig, type CubeSignerSession, type TwitterCodeExchangeParams } from "./cubeSignerAuth.js";
|
|
4
|
-
export type CubistLoginMethod = {
|
|
5
|
-
type: "google";
|
|
6
|
-
idToken: string;
|
|
7
|
-
} | {
|
|
8
|
-
type: "twitter";
|
|
9
|
-
params: TwitterCodeExchangeParams;
|
|
10
|
-
};
|
|
11
|
-
export interface CubistSessionAdapter {
|
|
12
|
-
/**
|
|
13
|
-
* Convert a raw CubeSigner session into a WalletSession
|
|
14
|
-
* (resolve the first key's address, chain, build a provider, etc.).
|
|
15
|
-
*/
|
|
16
|
-
resolve(session: CubeSignerSession): Promise<WalletSession>;
|
|
17
|
-
}
|
|
18
|
-
export declare class CubistSocialProvider extends AbstractSocialProvider {
|
|
19
|
-
readonly id = "cubist";
|
|
20
|
-
readonly title = "Cubist Social Wallet";
|
|
21
|
-
private auth;
|
|
22
|
-
private adapter;
|
|
23
|
-
private lastCubeSignerSession;
|
|
24
|
-
/** Stash the login method so `connect()` can auto-retry. */
|
|
25
|
-
private lastLogin;
|
|
26
|
-
constructor(config: CubeSignerConfig, adapter?: CubistSessionAdapter);
|
|
27
|
-
private createWalletSession;
|
|
28
|
-
private authenticate;
|
|
29
|
-
private getResolvedLoginMethod;
|
|
30
|
-
/**
|
|
31
|
-
* Preferred explicit sign-in entrypoint.
|
|
32
|
-
*/
|
|
33
|
-
signInWith(method: CubistLoginMethod, _options?: SocialLoginOptions): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Backward-compatible abstract implementation.
|
|
36
|
-
*
|
|
37
|
-
* - If `payload` is provided, it is treated as the login method.
|
|
38
|
-
* - Otherwise reuses the previously cached login method if available.
|
|
39
|
-
*/
|
|
40
|
-
signIn(_options?: SocialLoginOptions, payload?: unknown): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Explicit connect flow that both authenticates and returns the wallet session.
|
|
43
|
-
*/
|
|
44
|
-
connectWith(method: CubistLoginMethod, options?: SocialLoginOptions): Promise<WalletSession>;
|
|
45
|
-
connect(args?: WalletConnectArgs): Promise<WalletSession>;
|
|
46
|
-
reconnect(persistedSession: WalletSession): Promise<WalletSession | null>;
|
|
47
|
-
signOut(): Promise<void>;
|
|
48
|
-
disconnect(): Promise<void>;
|
|
49
|
-
/** Direct access to the underlying CubeSignerAuth for advanced use-cases. */
|
|
50
|
-
get cubeSignerAuth(): CubeSignerAuth;
|
|
51
|
-
get cubeSignerSession(): CubeSignerSession | null;
|
|
52
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { AbstractSocialProvider } from "./baseSocialProvider.js";
|
|
2
|
-
import { createSessionCapabilityPolicy, } from "../../core/capabilities.js";
|
|
3
|
-
import { createChainContext } from "../../core/chains.js";
|
|
4
|
-
import { CubeSignerAuth, } from "./cubeSignerAuth.js";
|
|
5
|
-
import { createCubistEvmWalletProvider } from "./cubistEvmWalletProvider.js";
|
|
6
|
-
/**
|
|
7
|
-
* Default adapter — returns the first Secp256k1.Evm key's material ID
|
|
8
|
-
* as the address on the ETH chain with an EVM-capable WalletProvider.
|
|
9
|
-
*/
|
|
10
|
-
const defaultAdapter = {
|
|
11
|
-
async resolve(session) {
|
|
12
|
-
const keys = await session.client.sessionKeys();
|
|
13
|
-
const evmKey = keys.find((k) => k.cached.key_type === "SecpEthAddr");
|
|
14
|
-
if (!evmKey)
|
|
15
|
-
throw new Error("No EVM key found in CubeSigner session");
|
|
16
|
-
const address = evmKey.materialId;
|
|
17
|
-
const chain = "ETH";
|
|
18
|
-
const provider = createCubistEvmWalletProvider({
|
|
19
|
-
session,
|
|
20
|
-
address,
|
|
21
|
-
chain,
|
|
22
|
-
});
|
|
23
|
-
return {
|
|
24
|
-
address,
|
|
25
|
-
chain,
|
|
26
|
-
provider,
|
|
27
|
-
chainContext: createChainContext(chain),
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
const cubistCapabilities = [
|
|
32
|
-
"eth_accounts",
|
|
33
|
-
"eth_requestAccounts",
|
|
34
|
-
"eth_chainId",
|
|
35
|
-
"eth_signTransaction",
|
|
36
|
-
"personal_sign",
|
|
37
|
-
"eth_signTypedData_v4",
|
|
38
|
-
"wallet_disconnect",
|
|
39
|
-
"wallet_rehydrate",
|
|
40
|
-
];
|
|
41
|
-
/* ─── Provider ──────────────────────────────── */
|
|
42
|
-
export class CubistSocialProvider extends AbstractSocialProvider {
|
|
43
|
-
constructor(config, adapter = defaultAdapter) {
|
|
44
|
-
super();
|
|
45
|
-
this.id = "cubist";
|
|
46
|
-
this.title = "Cubist Social Wallet";
|
|
47
|
-
this.lastCubeSignerSession = null;
|
|
48
|
-
/** Stash the login method so `connect()` can auto-retry. */
|
|
49
|
-
this.lastLogin = null;
|
|
50
|
-
this.auth = new CubeSignerAuth(config);
|
|
51
|
-
this.adapter = adapter;
|
|
52
|
-
}
|
|
53
|
-
async createWalletSession(method) {
|
|
54
|
-
const session = method.type === "google"
|
|
55
|
-
? await this.auth.loginWithGoogle(method.idToken)
|
|
56
|
-
: await this.auth.loginWithTwitter(method.params);
|
|
57
|
-
this.lastCubeSignerSession = session;
|
|
58
|
-
const walletSession = await this.adapter.resolve(session);
|
|
59
|
-
const capabilityPolicy = this.auth.defaultSessionPolicy
|
|
60
|
-
? createSessionCapabilityPolicy(this.auth.defaultSessionPolicy)
|
|
61
|
-
: undefined;
|
|
62
|
-
return {
|
|
63
|
-
...walletSession,
|
|
64
|
-
walletType: "social",
|
|
65
|
-
authSource: method.type,
|
|
66
|
-
sessionId: `${method.type}:${walletSession.address.toLowerCase()}`,
|
|
67
|
-
expiresAt: capabilityPolicy?.expiresAt,
|
|
68
|
-
capabilities: cubistCapabilities,
|
|
69
|
-
sessionData: session.sessionData,
|
|
70
|
-
chainContext: walletSession.chainContext ?? createChainContext(walletSession.chain),
|
|
71
|
-
capabilityPolicy,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
async authenticate(method) {
|
|
75
|
-
const walletSession = await this.createWalletSession(method);
|
|
76
|
-
this.lastLogin = method;
|
|
77
|
-
this.setSession(walletSession);
|
|
78
|
-
}
|
|
79
|
-
getResolvedLoginMethod(payload) {
|
|
80
|
-
const method = payload ?? this.lastLogin;
|
|
81
|
-
if (!method) {
|
|
82
|
-
throw new Error("CubistSocialProvider.signIn requires a login method. Use signInWith(method) first.");
|
|
83
|
-
}
|
|
84
|
-
return method;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Preferred explicit sign-in entrypoint.
|
|
88
|
-
*/
|
|
89
|
-
async signInWith(method, _options) {
|
|
90
|
-
await this.authenticate(method);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Backward-compatible abstract implementation.
|
|
94
|
-
*
|
|
95
|
-
* - If `payload` is provided, it is treated as the login method.
|
|
96
|
-
* - Otherwise reuses the previously cached login method if available.
|
|
97
|
-
*/
|
|
98
|
-
async signIn(_options, payload) {
|
|
99
|
-
await this.authenticate(this.getResolvedLoginMethod(payload));
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Explicit connect flow that both authenticates and returns the wallet session.
|
|
103
|
-
*/
|
|
104
|
-
async connectWith(method, options) {
|
|
105
|
-
return this.connect({ options, payload: method });
|
|
106
|
-
}
|
|
107
|
-
async connect(args) {
|
|
108
|
-
if (args?.payload !== undefined || args?.options !== undefined) {
|
|
109
|
-
await this.signIn(args.options, args.payload);
|
|
110
|
-
return this.requireSession("Cubist session missing after sign-in");
|
|
111
|
-
}
|
|
112
|
-
if (this.session) {
|
|
113
|
-
return this.session;
|
|
114
|
-
}
|
|
115
|
-
if (!this.lastLogin) {
|
|
116
|
-
throw new Error("Cubist session missing — call signInWith(method) first");
|
|
117
|
-
}
|
|
118
|
-
await this.signIn();
|
|
119
|
-
return this.requireSession("Cubist session missing after sign-in");
|
|
120
|
-
}
|
|
121
|
-
async reconnect(persistedSession) {
|
|
122
|
-
if (!persistedSession.sessionData)
|
|
123
|
-
return null;
|
|
124
|
-
try {
|
|
125
|
-
const csSession = await this.auth.restoreSession(persistedSession.sessionData);
|
|
126
|
-
this.lastCubeSignerSession = csSession;
|
|
127
|
-
const walletSession = await this.adapter.resolve(csSession);
|
|
128
|
-
return this.setSession({
|
|
129
|
-
...walletSession,
|
|
130
|
-
walletType: persistedSession.walletType ?? "social",
|
|
131
|
-
authSource: persistedSession.authSource,
|
|
132
|
-
sessionId: persistedSession.sessionId,
|
|
133
|
-
expiresAt: persistedSession.expiresAt,
|
|
134
|
-
capabilities: cubistCapabilities,
|
|
135
|
-
sessionData: csSession.sessionData,
|
|
136
|
-
chainContext: walletSession.chainContext ?? createChainContext(walletSession.chain),
|
|
137
|
-
capabilityPolicy: persistedSession.capabilityPolicy,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
catch {
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
async signOut() {
|
|
145
|
-
await this.auth.signOut();
|
|
146
|
-
this.clearSession();
|
|
147
|
-
this.lastLogin = null;
|
|
148
|
-
this.lastCubeSignerSession = null;
|
|
149
|
-
}
|
|
150
|
-
async disconnect() {
|
|
151
|
-
await this.signOut();
|
|
152
|
-
}
|
|
153
|
-
/** Direct access to the underlying CubeSignerAuth for advanced use-cases. */
|
|
154
|
-
get cubeSignerAuth() {
|
|
155
|
-
return this.auth;
|
|
156
|
-
}
|
|
157
|
-
get cubeSignerSession() {
|
|
158
|
-
return this.lastCubeSignerSession ?? this.auth.currentSession;
|
|
159
|
-
}
|
|
160
|
-
}
|