@buildersgarden/siwa 0.0.15 → 0.0.16
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/dist/signer/bankr.d.ts +51 -0
- package/dist/signer/bankr.js +123 -0
- package/dist/signer/index.d.ts +2 -0
- package/dist/signer/index.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bankr.ts
|
|
3
|
+
*
|
|
4
|
+
* Bankr wallet signer implementation.
|
|
5
|
+
*
|
|
6
|
+
* Uses the Bankr Agent API (https://api.bankr.bot) for signing operations.
|
|
7
|
+
* Wallet address is fetched via GET /agent/me, messages are signed via POST /agent/sign.
|
|
8
|
+
*/
|
|
9
|
+
import type { Signer } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for the Bankr SIWA signer.
|
|
12
|
+
*/
|
|
13
|
+
export interface BankrSiwaSignerConfig {
|
|
14
|
+
/** Bankr API key (or BANKR_API_KEY env var) */
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/** Bankr API base URL (defaults to https://api.bankr.bot) */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a SIWA Signer that wraps the Bankr Agent API.
|
|
21
|
+
*
|
|
22
|
+
* This signer implements the core Signer interface for SIWA message signing.
|
|
23
|
+
* It supports both standard message signing (EIP-191) and raw hex signing
|
|
24
|
+
* for ERC-8128 HTTP message signatures.
|
|
25
|
+
*
|
|
26
|
+
* The wallet address is fetched from the Bankr API on creation.
|
|
27
|
+
*
|
|
28
|
+
* @param config - Bankr API configuration
|
|
29
|
+
* @returns A Promise that resolves to a Signer compatible with SIWA's signSIWAMessage function
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { signSIWAMessage } from '@buildersgarden/siwa';
|
|
34
|
+
* import { createBankrSiwaSigner } from '@buildersgarden/siwa/signer';
|
|
35
|
+
*
|
|
36
|
+
* const signer = await createBankrSiwaSigner({
|
|
37
|
+
* apiKey: process.env.BANKR_API_KEY!,
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* const { message, signature, address } = await signSIWAMessage({
|
|
41
|
+
* domain: 'example.com',
|
|
42
|
+
* uri: 'https://example.com/login',
|
|
43
|
+
* agentId: 123,
|
|
44
|
+
* agentRegistry: 'eip155:84532:0x...',
|
|
45
|
+
* chainId: 84532,
|
|
46
|
+
* nonce: generateNonce(),
|
|
47
|
+
* issuedAt: new Date().toISOString(),
|
|
48
|
+
* }, signer);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function createBankrSiwaSigner(config?: BankrSiwaSignerConfig): Promise<Signer>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bankr.ts
|
|
3
|
+
*
|
|
4
|
+
* Bankr wallet signer implementation.
|
|
5
|
+
*
|
|
6
|
+
* Uses the Bankr Agent API (https://api.bankr.bot) for signing operations.
|
|
7
|
+
* Wallet address is fetched via GET /agent/me, messages are signed via POST /agent/sign.
|
|
8
|
+
*/
|
|
9
|
+
function resolveConfig(config) {
|
|
10
|
+
const apiKey = config.apiKey ?? process.env.BANKR_API_KEY;
|
|
11
|
+
if (!apiKey) {
|
|
12
|
+
throw new Error("Bankr API key is required. Provide apiKey in config or set BANKR_API_KEY env var.");
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
apiKey,
|
|
16
|
+
baseUrl: config.baseUrl ?? "https://api.bankr.bot",
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fetches the EVM wallet address from the Bankr API.
|
|
21
|
+
*/
|
|
22
|
+
async function fetchWalletAddress(config) {
|
|
23
|
+
const response = await fetch(`${config.baseUrl}/agent/me`, {
|
|
24
|
+
headers: {
|
|
25
|
+
"X-API-Key": config.apiKey,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
throw new Error(`Bankr API /agent/me failed: ${response.status} ${response.statusText}`);
|
|
30
|
+
}
|
|
31
|
+
const data = await response.json();
|
|
32
|
+
const evmWallet = data.wallets?.find((w) => w.chain === "evm");
|
|
33
|
+
if (!evmWallet?.address) {
|
|
34
|
+
throw new Error("No EVM wallet found in Bankr account");
|
|
35
|
+
}
|
|
36
|
+
return evmWallet.address;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Signs a message using the Bankr Agent API.
|
|
40
|
+
*/
|
|
41
|
+
async function bankrSign(config, signatureType, payload) {
|
|
42
|
+
const response = await fetch(`${config.baseUrl}/agent/sign`, {
|
|
43
|
+
method: "POST",
|
|
44
|
+
headers: {
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
"X-API-Key": config.apiKey,
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify({ signatureType, ...payload }),
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
throw new Error(`Bankr sign failed: ${response.status} ${response.statusText}`);
|
|
52
|
+
}
|
|
53
|
+
const result = await response.json();
|
|
54
|
+
if (!result.success || !result.signature) {
|
|
55
|
+
throw new Error(`Bankr sign failed: ${result.error ?? "no signature returned"}`);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
signature: result.signature,
|
|
59
|
+
signer: result.signer,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates a SIWA Signer that wraps the Bankr Agent API.
|
|
64
|
+
*
|
|
65
|
+
* This signer implements the core Signer interface for SIWA message signing.
|
|
66
|
+
* It supports both standard message signing (EIP-191) and raw hex signing
|
|
67
|
+
* for ERC-8128 HTTP message signatures.
|
|
68
|
+
*
|
|
69
|
+
* The wallet address is fetched from the Bankr API on creation.
|
|
70
|
+
*
|
|
71
|
+
* @param config - Bankr API configuration
|
|
72
|
+
* @returns A Promise that resolves to a Signer compatible with SIWA's signSIWAMessage function
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import { signSIWAMessage } from '@buildersgarden/siwa';
|
|
77
|
+
* import { createBankrSiwaSigner } from '@buildersgarden/siwa/signer';
|
|
78
|
+
*
|
|
79
|
+
* const signer = await createBankrSiwaSigner({
|
|
80
|
+
* apiKey: process.env.BANKR_API_KEY!,
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* const { message, signature, address } = await signSIWAMessage({
|
|
84
|
+
* domain: 'example.com',
|
|
85
|
+
* uri: 'https://example.com/login',
|
|
86
|
+
* agentId: 123,
|
|
87
|
+
* agentRegistry: 'eip155:84532:0x...',
|
|
88
|
+
* chainId: 84532,
|
|
89
|
+
* nonce: generateNonce(),
|
|
90
|
+
* issuedAt: new Date().toISOString(),
|
|
91
|
+
* }, signer);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export async function createBankrSiwaSigner(config = {}) {
|
|
95
|
+
const resolved = resolveConfig(config);
|
|
96
|
+
const walletAddress = await fetchWalletAddress(resolved);
|
|
97
|
+
return {
|
|
98
|
+
/**
|
|
99
|
+
* Returns the wallet address.
|
|
100
|
+
*/
|
|
101
|
+
async getAddress() {
|
|
102
|
+
return walletAddress;
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
* Signs a message using EIP-191 personal_sign.
|
|
106
|
+
* Used for standard SIWA message signing.
|
|
107
|
+
*/
|
|
108
|
+
async signMessage(message) {
|
|
109
|
+
const result = await bankrSign(resolved, "personal_sign", { message });
|
|
110
|
+
return result.signature;
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* Signs raw hex bytes.
|
|
114
|
+
* Used by ERC-8128 for HTTP message signatures.
|
|
115
|
+
*/
|
|
116
|
+
async signRawMessage(rawHex) {
|
|
117
|
+
const result = await bankrSign(resolved, "personal_sign", {
|
|
118
|
+
message: rawHex,
|
|
119
|
+
});
|
|
120
|
+
return result.signature;
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
package/dist/signer/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* - createCircleSiwaSigner(config) — Circle developer-controlled wallet
|
|
14
14
|
* - createCircleSiwaSignerFromClient(config) — Circle with existing client
|
|
15
15
|
* - createPrivySiwaSigner(config) — Privy server wallet
|
|
16
|
+
* - createBankrSiwaSigner(config) — Bankr Agent API wallet
|
|
16
17
|
*
|
|
17
18
|
* Usage:
|
|
18
19
|
* import { signSIWAMessage, createLocalAccountSigner } from '@buildersgarden/siwa';
|
|
@@ -28,3 +29,4 @@ export { createLocalAccountSigner } from './local-account.js';
|
|
|
28
29
|
export { createWalletClientSigner } from './wallet-client.js';
|
|
29
30
|
export { createCircleSiwaSigner, createCircleSiwaSignerFromClient, type CircleSiwaSignerConfig, type CircleSiwaSignerClientConfig, } from './circle.js';
|
|
30
31
|
export { createPrivySiwaSigner, type PrivySiwaSignerConfig, } from './privy.js';
|
|
32
|
+
export { createBankrSiwaSigner, type BankrSiwaSignerConfig, } from './bankr.js';
|
package/dist/signer/index.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* - createCircleSiwaSigner(config) — Circle developer-controlled wallet
|
|
14
14
|
* - createCircleSiwaSignerFromClient(config) — Circle with existing client
|
|
15
15
|
* - createPrivySiwaSigner(config) — Privy server wallet
|
|
16
|
+
* - createBankrSiwaSigner(config) — Bankr Agent API wallet
|
|
16
17
|
*
|
|
17
18
|
* Usage:
|
|
18
19
|
* import { signSIWAMessage, createLocalAccountSigner } from '@buildersgarden/siwa';
|
|
@@ -28,3 +29,4 @@ export { createLocalAccountSigner } from './local-account.js';
|
|
|
28
29
|
export { createWalletClientSigner } from './wallet-client.js';
|
|
29
30
|
export { createCircleSiwaSigner, createCircleSiwaSignerFromClient, } from './circle.js';
|
|
30
31
|
export { createPrivySiwaSigner, } from './privy.js';
|
|
32
|
+
export { createBankrSiwaSigner, } from './bankr.js';
|