@buildersgarden/siwa 0.0.15 → 0.0.17
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 +1 -1
- package/dist/registry.d.ts +40 -1
- package/dist/registry.js +36 -0
- 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
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ See [`references/security-model.md`](references/security-model.md) for the full
|
|
|
64
64
|
|
|
65
65
|
## References
|
|
66
66
|
|
|
67
|
-
- [
|
|
67
|
+
- [skill.md](skill.md) — Full skill documentation and API reference
|
|
68
68
|
- [ERC-8004 specification](https://github.com/builders-garden/ERC-8004)
|
|
69
69
|
- [SIWA protocol spec](references/siwa-spec.md)
|
|
70
70
|
|
package/dist/registry.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Dependencies:
|
|
8
8
|
* npm install viem
|
|
9
9
|
*/
|
|
10
|
-
import { type PublicClient } from 'viem';
|
|
10
|
+
import { type PublicClient, type Address, type Hex } from 'viem';
|
|
11
11
|
import type { TransactionSigner } from './signer/index.js';
|
|
12
12
|
/** Service endpoint types defined in ERC-8004 */
|
|
13
13
|
export type ServiceType = 'web' | 'A2A' | 'MCP' | 'OASF' | 'ENS' | 'DID' | 'email';
|
|
@@ -73,6 +73,45 @@ export declare function getAgent(agentId: number, options: GetAgentOptions): Pro
|
|
|
73
73
|
* @param options Reputation registry address, client, and optional filters
|
|
74
74
|
*/
|
|
75
75
|
export declare function getReputation(agentId: number, options: GetReputationOptions): Promise<ReputationSummary>;
|
|
76
|
+
export interface EncodeRegisterAgentOptions {
|
|
77
|
+
/** The agent metadata URI (IPFS, HTTP, or data URL) */
|
|
78
|
+
agentURI: string;
|
|
79
|
+
/** The chain ID to register on */
|
|
80
|
+
chainId: number;
|
|
81
|
+
}
|
|
82
|
+
export interface EncodeRegisterAgentResult {
|
|
83
|
+
/** The registry contract address */
|
|
84
|
+
to: Address;
|
|
85
|
+
/** The ABI-encoded calldata for `register(agentURI)` */
|
|
86
|
+
data: Hex;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Encode the calldata for an ERC-8004 agent registration without sending it.
|
|
90
|
+
*
|
|
91
|
+
* Use this when your wallet provider handles transaction submission separately
|
|
92
|
+
* (e.g. Bankr's `/agent/submit`, or any ERC-4337 bundler).
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { encodeRegisterAgent } from '@buildersgarden/siwa/registry';
|
|
97
|
+
*
|
|
98
|
+
* const { to, data } = encodeRegisterAgent({
|
|
99
|
+
* agentURI: 'data:application/json;base64,...',
|
|
100
|
+
* chainId: 84532,
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* // Submit via your provider (e.g. Bankr)
|
|
104
|
+
* await fetch('https://api.bankr.bot/agent/submit', {
|
|
105
|
+
* method: 'POST',
|
|
106
|
+
* headers: { 'Content-Type': 'application/json', 'X-API-Key': apiKey },
|
|
107
|
+
* body: JSON.stringify({
|
|
108
|
+
* transaction: { to, data, value: '0', chainId: 84532 },
|
|
109
|
+
* waitForConfirmation: true,
|
|
110
|
+
* }),
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function encodeRegisterAgent(options: EncodeRegisterAgentOptions): EncodeRegisterAgentResult;
|
|
76
115
|
export interface RegisterAgentOptions {
|
|
77
116
|
/** The agent metadata URI (IPFS, HTTP, or data URL) */
|
|
78
117
|
agentURI: string;
|
package/dist/registry.js
CHANGED
|
@@ -156,6 +156,42 @@ export async function getReputation(agentId, options) {
|
|
|
156
156
|
const score = Number(rawValue) / 10 ** decimals;
|
|
157
157
|
return { count: Number(count), score, rawValue, decimals };
|
|
158
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Encode the calldata for an ERC-8004 agent registration without sending it.
|
|
161
|
+
*
|
|
162
|
+
* Use this when your wallet provider handles transaction submission separately
|
|
163
|
+
* (e.g. Bankr's `/agent/submit`, or any ERC-4337 bundler).
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* import { encodeRegisterAgent } from '@buildersgarden/siwa/registry';
|
|
168
|
+
*
|
|
169
|
+
* const { to, data } = encodeRegisterAgent({
|
|
170
|
+
* agentURI: 'data:application/json;base64,...',
|
|
171
|
+
* chainId: 84532,
|
|
172
|
+
* });
|
|
173
|
+
*
|
|
174
|
+
* // Submit via your provider (e.g. Bankr)
|
|
175
|
+
* await fetch('https://api.bankr.bot/agent/submit', {
|
|
176
|
+
* method: 'POST',
|
|
177
|
+
* headers: { 'Content-Type': 'application/json', 'X-API-Key': apiKey },
|
|
178
|
+
* body: JSON.stringify({
|
|
179
|
+
* transaction: { to, data, value: '0', chainId: 84532 },
|
|
180
|
+
* waitForConfirmation: true,
|
|
181
|
+
* }),
|
|
182
|
+
* });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export function encodeRegisterAgent(options) {
|
|
186
|
+
const { agentURI, chainId } = options;
|
|
187
|
+
const registryAddress = getRegistryAddress(chainId);
|
|
188
|
+
const data = encodeFunctionData({
|
|
189
|
+
abi: IDENTITY_REGISTRY_ABI,
|
|
190
|
+
functionName: 'register',
|
|
191
|
+
args: [agentURI],
|
|
192
|
+
});
|
|
193
|
+
return { to: registryAddress, data };
|
|
194
|
+
}
|
|
159
195
|
/**
|
|
160
196
|
* Register an agent on the ERC-8004 Identity Registry in a single call.
|
|
161
197
|
*
|
|
@@ -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';
|