@zeroxyz/sdk 0.12.0 → 0.13.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/CHANGELOG.md +9 -0
- package/README.md +16 -3
- package/dist/{chunk-O7424YAR.cjs → chunk-2A2ZZ5XR.cjs} +164 -44
- package/dist/chunk-2A2ZZ5XR.cjs.map +1 -0
- package/dist/{chunk-KDWESC42.js → chunk-CYB4Y3ID.js} +164 -44
- package/dist/chunk-CYB4Y3ID.js.map +1 -0
- package/dist/{client-DLwdMDSu.d.cts → client-C23Vw9bv.d.cts} +30 -3
- package/dist/{client-DLwdMDSu.d.ts → client-C23Vw9bv.d.ts} +30 -3
- package/dist/index.cjs +44 -44
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +2 -2
- package/dist/testing.cjs +2 -2
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-KDWESC42.js.map +0 -1
- package/dist/chunk-O7424YAR.cjs.map +0 -1
|
@@ -13,36 +13,40 @@ import { createHash } from 'crypto';
|
|
|
13
13
|
import { z } from 'zod';
|
|
14
14
|
|
|
15
15
|
// src/auth/managed-account.ts
|
|
16
|
-
var createManagedAccount = (client, address) =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
16
|
+
var createManagedAccount = (client, address, opts = {}) => {
|
|
17
|
+
const signOptions = {
|
|
18
|
+
// expectedAddress pins verification to this adapter's frozen address.
|
|
19
|
+
expectedAddress: address,
|
|
20
|
+
...opts.explicitWallet ? { walletAddress: address } : {}
|
|
21
|
+
};
|
|
22
|
+
return toAccount({
|
|
23
|
+
address,
|
|
24
|
+
async signMessage({ message }) {
|
|
25
|
+
return await client.auth.signMessage({ message }, signOptions);
|
|
26
|
+
},
|
|
27
|
+
async signTypedData(typedData) {
|
|
28
|
+
const td = typedData;
|
|
29
|
+
return await client.auth.signTypedData(
|
|
30
|
+
{
|
|
31
|
+
domain: td.domain,
|
|
32
|
+
types: td.types,
|
|
33
|
+
primaryType: td.primaryType,
|
|
34
|
+
message: td.message
|
|
35
|
+
},
|
|
36
|
+
signOptions
|
|
37
|
+
);
|
|
38
|
+
},
|
|
39
|
+
async signTransaction(transaction, options) {
|
|
40
|
+
const serialize = options?.serializer ?? serializeTransaction;
|
|
41
|
+
const unsigned = await serialize(transaction);
|
|
42
|
+
const signature = await client.auth.signTransaction(
|
|
43
|
+
{ unsignedTransaction: unsigned },
|
|
44
|
+
signOptions
|
|
45
|
+
);
|
|
46
|
+
return await serialize(transaction, parseSignature(signature));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
46
50
|
var USDC_BASE = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913";
|
|
47
51
|
var USDC_TEMPO = "0x20c000000000000000000000b9537d11c60e8b50";
|
|
48
52
|
var TEMPO_CHAIN_ID = 4217;
|
|
@@ -639,12 +643,12 @@ var cancelBody = (response) => {
|
|
|
639
643
|
} catch {
|
|
640
644
|
}
|
|
641
645
|
};
|
|
642
|
-
var resolveAccount = async (client, overrideAccount, signal) => {
|
|
646
|
+
var resolveAccount = async (client, overrideAccount, signal, walletAddress) => {
|
|
643
647
|
if (overrideAccount) return overrideAccount;
|
|
644
648
|
const credentials = client.getCredentials();
|
|
645
649
|
if (credentials.kind === "account") return credentials.account;
|
|
646
650
|
if (credentials.kind === "session") {
|
|
647
|
-
return await client.resolveManagedAccount(signal);
|
|
651
|
+
return await client.resolveManagedAccount(signal, walletAddress);
|
|
648
652
|
}
|
|
649
653
|
throw new ZeroAuthError(
|
|
650
654
|
"auth_no_credentials",
|
|
@@ -690,7 +694,8 @@ var Payments = class {
|
|
|
690
694
|
const account = await resolveAccount(
|
|
691
695
|
this.client,
|
|
692
696
|
input.account,
|
|
693
|
-
input.signal
|
|
697
|
+
input.signal,
|
|
698
|
+
input.walletAddress
|
|
694
699
|
);
|
|
695
700
|
let capturedAmount = null;
|
|
696
701
|
let capturedNetwork;
|
|
@@ -825,7 +830,8 @@ var Payments = class {
|
|
|
825
830
|
const account = await resolveAccount(
|
|
826
831
|
this.client,
|
|
827
832
|
input.account,
|
|
828
|
-
input.signal
|
|
833
|
+
input.signal,
|
|
834
|
+
input.walletAddress
|
|
829
835
|
);
|
|
830
836
|
const configuredFetch = buildConfiguredFetch(this.client, {
|
|
831
837
|
timeoutMs: input.timeoutMs
|
|
@@ -1605,7 +1611,8 @@ var recordErrorFetchRun = async (client, opts, result, capabilityIdOverride) =>
|
|
|
1605
1611
|
...fetchOriginForRecord && { fetchOrigin: fetchOriginForRecord },
|
|
1606
1612
|
...result.status !== null && { status: result.status },
|
|
1607
1613
|
latencyMs: result.latencyMs,
|
|
1608
|
-
...opts.requestSchema && { requestSchema: opts.requestSchema }
|
|
1614
|
+
...opts.requestSchema && { requestSchema: opts.requestSchema },
|
|
1615
|
+
...opts.walletAddress && !opts.account && { walletAddress: opts.walletAddress }
|
|
1609
1616
|
});
|
|
1610
1617
|
result.runId = created.runId;
|
|
1611
1618
|
delete result.runTrackingSkipped;
|
|
@@ -1714,6 +1721,7 @@ var clientFetch = async (client, url, opts = {}) => {
|
|
|
1714
1721
|
body: requestBody,
|
|
1715
1722
|
maxPay: opts.maxPay,
|
|
1716
1723
|
account: opts.account,
|
|
1724
|
+
...opts.walletAddress && { walletAddress: opts.walletAddress },
|
|
1717
1725
|
signal: opts.signal,
|
|
1718
1726
|
timeoutMs: opts.timeoutMs,
|
|
1719
1727
|
...opts.displayCostAmount && {
|
|
@@ -1886,6 +1894,10 @@ var clientFetch = async (client, url, opts = {}) => {
|
|
|
1886
1894
|
...opts.capabilityId === void 0 ? { fetchOrigin: "direct_url" } : opts.fetchOrigin && { fetchOrigin: opts.fetchOrigin },
|
|
1887
1895
|
status: response.status,
|
|
1888
1896
|
latencyMs,
|
|
1897
|
+
// Attribute to the selected wallet in session mode. Skipped when a
|
|
1898
|
+
// per-call `account` override records the run — that account's own
|
|
1899
|
+
// EIP-191 identity is the attribution.
|
|
1900
|
+
...opts.walletAddress && !opts.account && { walletAddress: opts.walletAddress },
|
|
1889
1901
|
...opts.requestSchema && { requestSchema: opts.requestSchema },
|
|
1890
1902
|
...derived?.responseSchema && {
|
|
1891
1903
|
responseSchema: derived.responseSchema
|
|
@@ -1951,7 +1963,7 @@ var clientFetch = async (client, url, opts = {}) => {
|
|
|
1951
1963
|
|
|
1952
1964
|
// package.json
|
|
1953
1965
|
var package_default = {
|
|
1954
|
-
version: "0.
|
|
1966
|
+
version: "0.13.0"};
|
|
1955
1967
|
|
|
1956
1968
|
// src/version.ts
|
|
1957
1969
|
var SDK_VERSION = package_default.version;
|
|
@@ -2441,6 +2453,9 @@ var userWalletDtoSchema = z.object({
|
|
|
2441
2453
|
walletAddress: z.string(),
|
|
2442
2454
|
source: z.enum(["self_custody", "privy_embedded"]),
|
|
2443
2455
|
isPrimary: z.boolean(),
|
|
2456
|
+
// Owner-chosen display name; null/absent = unnamed (show the address).
|
|
2457
|
+
// Optional so the SDK tolerates servers that predate nicknames.
|
|
2458
|
+
nickname: z.string().nullable().optional(),
|
|
2444
2459
|
linkedAt: z.union([z.string(), z.date()]).nullable().optional(),
|
|
2445
2460
|
importedAt: z.union([z.string(), z.date()]).nullable().optional(),
|
|
2446
2461
|
delegationGranted: z.boolean(),
|
|
@@ -2658,7 +2673,10 @@ var Auth = class {
|
|
|
2658
2673
|
{
|
|
2659
2674
|
method: "POST",
|
|
2660
2675
|
path: "/v1/users/me/sign-message",
|
|
2661
|
-
body: {
|
|
2676
|
+
body: {
|
|
2677
|
+
message: normalizeMessage(input.message),
|
|
2678
|
+
...opts.walletAddress ? { walletAddress: opts.walletAddress } : {}
|
|
2679
|
+
}
|
|
2662
2680
|
},
|
|
2663
2681
|
signResponseSchema
|
|
2664
2682
|
);
|
|
@@ -2683,7 +2701,10 @@ var Auth = class {
|
|
|
2683
2701
|
{
|
|
2684
2702
|
method: "POST",
|
|
2685
2703
|
path: "/v1/users/me/sign-transaction",
|
|
2686
|
-
body: {
|
|
2704
|
+
body: {
|
|
2705
|
+
unsignedTransaction: input.unsignedTransaction,
|
|
2706
|
+
...opts.walletAddress ? { walletAddress: opts.walletAddress } : {}
|
|
2707
|
+
}
|
|
2687
2708
|
},
|
|
2688
2709
|
signResponseSchema
|
|
2689
2710
|
);
|
|
@@ -2722,7 +2743,10 @@ var Auth = class {
|
|
|
2722
2743
|
{
|
|
2723
2744
|
method: "POST",
|
|
2724
2745
|
path: "/v1/users/me/sign-typed-data",
|
|
2725
|
-
body: {
|
|
2746
|
+
body: {
|
|
2747
|
+
typedData: input,
|
|
2748
|
+
...opts.walletAddress ? { walletAddress: opts.walletAddress } : {}
|
|
2749
|
+
}
|
|
2726
2750
|
},
|
|
2727
2751
|
signResponseSchema
|
|
2728
2752
|
);
|
|
@@ -3099,6 +3123,9 @@ var Runs = class {
|
|
|
3099
3123
|
if (params.unreviewed !== void 0) query.unreviewed = params.unreviewed;
|
|
3100
3124
|
if (params.limit !== void 0) query.limit = params.limit;
|
|
3101
3125
|
if (params.cursor !== void 0) query.cursor = params.cursor;
|
|
3126
|
+
if (params.walletAddress !== void 0) {
|
|
3127
|
+
query.walletAddress = Array.isArray(params.walletAddress) ? params.walletAddress.join(",") : params.walletAddress;
|
|
3128
|
+
}
|
|
3102
3129
|
return request(
|
|
3103
3130
|
this.client,
|
|
3104
3131
|
{
|
|
@@ -3234,6 +3261,50 @@ var Wallet = class {
|
|
|
3234
3261
|
},
|
|
3235
3262
|
userWalletDtoSchema
|
|
3236
3263
|
);
|
|
3264
|
+
// Re-stamp Zero's signing delegation on a profile wallet (default: the
|
|
3265
|
+
// primary). Session-only. Naming a wallet re-authorizes THAT wallet and
|
|
3266
|
+
// never provisions; the server 404s an address not on the profile.
|
|
3267
|
+
reauthorizeDelegation = (opts = {}) => request(
|
|
3268
|
+
this.client,
|
|
3269
|
+
{
|
|
3270
|
+
method: "POST",
|
|
3271
|
+
path: "/v1/users/me/wallets/provision",
|
|
3272
|
+
...opts.walletAddress ? { body: { walletAddress: opts.walletAddress } } : {},
|
|
3273
|
+
signal: opts.signal
|
|
3274
|
+
},
|
|
3275
|
+
userWalletDtoSchema
|
|
3276
|
+
);
|
|
3277
|
+
// Revoke Zero's signing delegation on a profile wallet (default: the
|
|
3278
|
+
// primary). Session-only. Managed signing on that wallet 403s until it is
|
|
3279
|
+
// re-authorized. Note: this stamps the server-side gate — removing Zero's
|
|
3280
|
+
// signer cryptographically is owner-authorized and happens in the user's
|
|
3281
|
+
// Privy session (the web profile page does both).
|
|
3282
|
+
revokeDelegation = (opts = {}) => request(
|
|
3283
|
+
this.client,
|
|
3284
|
+
{
|
|
3285
|
+
method: "DELETE",
|
|
3286
|
+
path: "/v1/users/me/wallets/delegation",
|
|
3287
|
+
...opts.walletAddress ? { query: { walletAddress: opts.walletAddress } } : {},
|
|
3288
|
+
signal: opts.signal
|
|
3289
|
+
},
|
|
3290
|
+
userWalletDtoSchema
|
|
3291
|
+
);
|
|
3292
|
+
// Set, change, or clear (null / empty string) the owner-chosen nickname on
|
|
3293
|
+
// a profile wallet. Session-only. Nicknames are private to the
|
|
3294
|
+
// authenticated user — they never appear on reviews or public surfaces.
|
|
3295
|
+
setNickname = (opts) => request(
|
|
3296
|
+
this.client,
|
|
3297
|
+
{
|
|
3298
|
+
method: "PATCH",
|
|
3299
|
+
path: "/v1/users/me/wallets/nickname",
|
|
3300
|
+
body: {
|
|
3301
|
+
walletAddress: opts.walletAddress,
|
|
3302
|
+
nickname: opts.nickname
|
|
3303
|
+
},
|
|
3304
|
+
signal: opts.signal
|
|
3305
|
+
},
|
|
3306
|
+
userWalletDtoSchema
|
|
3307
|
+
);
|
|
3237
3308
|
// Link an existing self-custody wallet to the session user by private key.
|
|
3238
3309
|
// Session-only. 409s when the wallet is already linked (to this or another
|
|
3239
3310
|
// profile — the error message says which).
|
|
@@ -3244,7 +3315,8 @@ var Wallet = class {
|
|
|
3244
3315
|
path: "/v1/users/me/wallets/import",
|
|
3245
3316
|
body: {
|
|
3246
3317
|
privateKey: opts.privateKey,
|
|
3247
|
-
...opts.makePrimary !== void 0 ? { makePrimary: opts.makePrimary } : {}
|
|
3318
|
+
...opts.makePrimary !== void 0 ? { makePrimary: opts.makePrimary } : {},
|
|
3319
|
+
...opts.nickname !== void 0 ? { nickname: opts.nickname } : {}
|
|
3248
3320
|
},
|
|
3249
3321
|
signal: opts.signal
|
|
3250
3322
|
},
|
|
@@ -3447,6 +3519,9 @@ var ZeroClient = class _ZeroClient {
|
|
|
3447
3519
|
managedAccountInFlight = null;
|
|
3448
3520
|
managedAccountAC = null;
|
|
3449
3521
|
managedAccountGen = 0;
|
|
3522
|
+
// Explicitly-selected (non-default) managed wallets, keyed by lowercased
|
|
3523
|
+
// address. Same lifecycle as managedAccount: cleared on clearManagedAccount.
|
|
3524
|
+
managedAccountByAddress = /* @__PURE__ */ new Map();
|
|
3450
3525
|
// Multi-tenant servers calling `client.fetch(url, { account: tenantAccount })`
|
|
3451
3526
|
// on every request would otherwise construct a new ZeroClient (with
|
|
3452
3527
|
// five namespace instances) per call. Keyed by lowercased account
|
|
@@ -3668,8 +3743,16 @@ var ZeroClient = class _ZeroClient {
|
|
|
3668
3743
|
}
|
|
3669
3744
|
this.withAccountCache.clear();
|
|
3670
3745
|
};
|
|
3671
|
-
/**
|
|
3672
|
-
|
|
3746
|
+
/**
|
|
3747
|
+
* @internal — used by payments.pay() in session mode. Cached, dedupes
|
|
3748
|
+
* concurrent lookups. Pass `walletAddress` to sign as a specific profile
|
|
3749
|
+
* wallet instead of the primary; explicit wallets are cached per address
|
|
3750
|
+
* and their sign requests carry the address so intent and signer agree.
|
|
3751
|
+
*/
|
|
3752
|
+
resolveManagedAccount = (signal, walletAddress) => {
|
|
3753
|
+
if (walletAddress) {
|
|
3754
|
+
return this.resolveManagedAccountByAddress(walletAddress, signal);
|
|
3755
|
+
}
|
|
3673
3756
|
if (this.managedAccount) return Promise.resolve(this.managedAccount);
|
|
3674
3757
|
if (this.managedAccountInFlight) {
|
|
3675
3758
|
return this.raceWithSignal(this.managedAccountInFlight, signal);
|
|
@@ -3711,6 +3794,42 @@ var ZeroClient = class _ZeroClient {
|
|
|
3711
3794
|
});
|
|
3712
3795
|
return this.raceWithSignal(this.managedAccountInFlight, signal);
|
|
3713
3796
|
};
|
|
3797
|
+
// Explicit-wallet variant of resolveManagedAccount. No in-flight dedupe:
|
|
3798
|
+
// this is the rare path (per-wallet pay), the resolution is idempotent, and
|
|
3799
|
+
// the per-address cache absorbs repeat calls.
|
|
3800
|
+
resolveManagedAccountByAddress = async (walletAddress, signal) => {
|
|
3801
|
+
if (this.credentials.kind !== "session") {
|
|
3802
|
+
throw new ZeroAuthError(
|
|
3803
|
+
"auth_no_credentials",
|
|
3804
|
+
"resolveManagedAccount() requires session credentials."
|
|
3805
|
+
);
|
|
3806
|
+
}
|
|
3807
|
+
const canonical = getAddress(walletAddress);
|
|
3808
|
+
const cached = this.managedAccountByAddress.get(canonical.toLowerCase());
|
|
3809
|
+
if (cached) return cached;
|
|
3810
|
+
const startedAtGen = this.managedAccountGen;
|
|
3811
|
+
const wallets = await this.auth.wallets({ signal });
|
|
3812
|
+
const match = wallets.find(
|
|
3813
|
+
(w) => w.walletAddress.toLowerCase() === canonical.toLowerCase()
|
|
3814
|
+
);
|
|
3815
|
+
if (!match || match.source !== "privy_embedded") {
|
|
3816
|
+
throw new ZeroAuthError(
|
|
3817
|
+
"auth_error",
|
|
3818
|
+
`Wallet ${canonical} is not a Privy-embedded wallet on this profile. Managed signing can only use profile wallets (see client.wallet.list()).`
|
|
3819
|
+
);
|
|
3820
|
+
}
|
|
3821
|
+
if (this.managedAccountGen !== startedAtGen) {
|
|
3822
|
+
throw new ZeroAuthError(
|
|
3823
|
+
"auth_session_expired",
|
|
3824
|
+
"Session cleared during managed-account resolution. Retry to rebuild against the current session."
|
|
3825
|
+
);
|
|
3826
|
+
}
|
|
3827
|
+
const acc = createManagedAccount(this, canonical, {
|
|
3828
|
+
explicitWallet: true
|
|
3829
|
+
});
|
|
3830
|
+
this.managedAccountByAddress.set(canonical.toLowerCase(), acc);
|
|
3831
|
+
return acc;
|
|
3832
|
+
};
|
|
3714
3833
|
// Per-caller signal gate: each caller can reject on their own abort
|
|
3715
3834
|
// without cancelling the shared underlying promise.
|
|
3716
3835
|
raceWithSignal = (p, signal) => {
|
|
@@ -3741,6 +3860,7 @@ var ZeroClient = class _ZeroClient {
|
|
|
3741
3860
|
this.managedAccountAC?.abort();
|
|
3742
3861
|
this.managedAccountInFlight = null;
|
|
3743
3862
|
this.managedAccountAC = null;
|
|
3863
|
+
this.managedAccountByAddress.clear();
|
|
3744
3864
|
this.managedAccountGen++;
|
|
3745
3865
|
};
|
|
3746
3866
|
/** @internal — Read cached managed account without triggering resolution. */
|
|
@@ -3794,5 +3914,5 @@ var ZeroClient = class _ZeroClient {
|
|
|
3794
3914
|
};
|
|
3795
3915
|
|
|
3796
3916
|
export { Auth, AuthAgent, AuthDevice, BUG_REPORT_CATEGORIES, BugReports, Capabilities, DEFAULT_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS, FETCH_SKIP_REASONS, FETCH_WARNINGS, Payments, Runs, SDK_VERSION, TEMPO_CHAIN_ID2 as TEMPO_CHAIN_ID, TEMPO_TESTNET_CHAIN_ID, USDC_BASE, USDC_DECIMALS, USDC_TEMPO, Wallet, ZeroAgentAuthError, ZeroApiError, ZeroAuthError, ZeroClient, ZeroConfigurationError, ZeroError, ZeroPaymentError, ZeroSessionCloseFailedError, ZeroTimeoutError, ZeroValidationError, ZeroWalletError, asSchemaNode, coerceTempoChainId, createManagedAccount, extractInputEnvelope, isShortToken, normalizeTransportEnvelopeRequest, paymentHasAnchor, tempoChainLabelFromId, unwrapTransportEnvelope };
|
|
3797
|
-
//# sourceMappingURL=chunk-
|
|
3798
|
-
//# sourceMappingURL=chunk-
|
|
3917
|
+
//# sourceMappingURL=chunk-CYB4Y3ID.js.map
|
|
3918
|
+
//# sourceMappingURL=chunk-CYB4Y3ID.js.map
|