@proofchain/sdk 2.10.0 → 2.11.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/dist/index.d.mts CHANGED
@@ -1630,6 +1630,25 @@ interface WalletCreationResult {
1630
1630
  network?: string;
1631
1631
  source: string;
1632
1632
  }
1633
+ interface EnsureWalletResult {
1634
+ user_id: string;
1635
+ asset_wallet: {
1636
+ wallet_id: string;
1637
+ address: string;
1638
+ wallet_type: string;
1639
+ network: string;
1640
+ [key: string]: any;
1641
+ };
1642
+ smart_wallet: {
1643
+ wallet_id: string;
1644
+ address: string;
1645
+ wallet_type: string;
1646
+ network: string;
1647
+ [key: string]: any;
1648
+ };
1649
+ network: string;
1650
+ created: boolean;
1651
+ }
1633
1652
  interface SetProfileRequest {
1634
1653
  email?: string;
1635
1654
  first_name?: string;
@@ -1720,33 +1739,33 @@ declare class EndUsersClient {
1720
1739
  */
1721
1740
  registerWallet(externalId: string, request: RegisterWalletRequest): Promise<WalletCreationResult>;
1722
1741
  /**
1723
- * Ensure a user has a wallet, creating one if they don't.
1742
+ * Ensure a user has dual wallets (EOA + Smart Account), creating them if they don't exist.
1724
1743
  *
1725
- * This is the recommended way for frontend devs to guarantee a wallet
1726
- * exists before performing any wallet-dependent operation (e.g. attestation,
1744
+ * This is the recommended way for frontend devs to guarantee wallets exist
1745
+ * before performing any wallet-dependent operation (e.g. attestation,
1727
1746
  * on-chain claims, token transfers).
1728
1747
  *
1729
- * If the user already has a wallet, returns immediately with the existing
1730
- * address. If not, creates a CDP wallet with the specified options.
1748
+ * If the user already has both wallet types, returns them immediately.
1749
+ * If not, creates a dual wallet pair (EOA asset wallet + Smart Account
1750
+ * for gasless transactions) via the CDP SDK.
1731
1751
  *
1732
1752
  * @param externalId - The user's external ID
1733
- * @param options - Wallet creation options (only used if a new wallet is created)
1734
- * @returns Wallet result with address and creation status
1753
+ * @param network - Network to create wallets on (default: 'base-sepolia')
1754
+ * @returns EnsureWalletResult with both wallets and whether they were newly created
1735
1755
  *
1736
1756
  * @example
1737
1757
  * ```typescript
1738
1758
  * // One-liner before any wallet-dependent operation
1739
- * const wallet = await client.users.ensureWallet('user-123');
1740
- * console.log(wallet.wallet_address); // '0xabc...'
1759
+ * const result = await client.users.ensureWallet('user-123');
1760
+ * console.log(result.asset_wallet.address); // '0xabc...'
1761
+ * console.log(result.smart_wallet.address); // '0xdef...'
1762
+ * console.log(result.created); // false if they already existed
1741
1763
  *
1742
- * // With options
1743
- * const wallet = await client.users.ensureWallet('user-123', {
1744
- * wallet_type: 'eoa',
1745
- * network: 'base-mainnet',
1746
- * });
1764
+ * // With specific network
1765
+ * const result = await client.users.ensureWallet('user-123', 'base-mainnet');
1747
1766
  * ```
1748
1767
  */
1749
- ensureWallet(externalId: string, options?: CreateWalletRequest): Promise<WalletCreationResult>;
1768
+ ensureWallet(externalId: string, network?: string): Promise<EnsureWalletResult>;
1750
1769
  /**
1751
1770
  * Update user attributes (convenience method) by external ID.
1752
1771
  * Merges the provided attributes into the existing attributes object.
package/dist/index.d.ts CHANGED
@@ -1630,6 +1630,25 @@ interface WalletCreationResult {
1630
1630
  network?: string;
1631
1631
  source: string;
1632
1632
  }
1633
+ interface EnsureWalletResult {
1634
+ user_id: string;
1635
+ asset_wallet: {
1636
+ wallet_id: string;
1637
+ address: string;
1638
+ wallet_type: string;
1639
+ network: string;
1640
+ [key: string]: any;
1641
+ };
1642
+ smart_wallet: {
1643
+ wallet_id: string;
1644
+ address: string;
1645
+ wallet_type: string;
1646
+ network: string;
1647
+ [key: string]: any;
1648
+ };
1649
+ network: string;
1650
+ created: boolean;
1651
+ }
1633
1652
  interface SetProfileRequest {
1634
1653
  email?: string;
1635
1654
  first_name?: string;
@@ -1720,33 +1739,33 @@ declare class EndUsersClient {
1720
1739
  */
1721
1740
  registerWallet(externalId: string, request: RegisterWalletRequest): Promise<WalletCreationResult>;
1722
1741
  /**
1723
- * Ensure a user has a wallet, creating one if they don't.
1742
+ * Ensure a user has dual wallets (EOA + Smart Account), creating them if they don't exist.
1724
1743
  *
1725
- * This is the recommended way for frontend devs to guarantee a wallet
1726
- * exists before performing any wallet-dependent operation (e.g. attestation,
1744
+ * This is the recommended way for frontend devs to guarantee wallets exist
1745
+ * before performing any wallet-dependent operation (e.g. attestation,
1727
1746
  * on-chain claims, token transfers).
1728
1747
  *
1729
- * If the user already has a wallet, returns immediately with the existing
1730
- * address. If not, creates a CDP wallet with the specified options.
1748
+ * If the user already has both wallet types, returns them immediately.
1749
+ * If not, creates a dual wallet pair (EOA asset wallet + Smart Account
1750
+ * for gasless transactions) via the CDP SDK.
1731
1751
  *
1732
1752
  * @param externalId - The user's external ID
1733
- * @param options - Wallet creation options (only used if a new wallet is created)
1734
- * @returns Wallet result with address and creation status
1753
+ * @param network - Network to create wallets on (default: 'base-sepolia')
1754
+ * @returns EnsureWalletResult with both wallets and whether they were newly created
1735
1755
  *
1736
1756
  * @example
1737
1757
  * ```typescript
1738
1758
  * // One-liner before any wallet-dependent operation
1739
- * const wallet = await client.users.ensureWallet('user-123');
1740
- * console.log(wallet.wallet_address); // '0xabc...'
1759
+ * const result = await client.users.ensureWallet('user-123');
1760
+ * console.log(result.asset_wallet.address); // '0xabc...'
1761
+ * console.log(result.smart_wallet.address); // '0xdef...'
1762
+ * console.log(result.created); // false if they already existed
1741
1763
  *
1742
- * // With options
1743
- * const wallet = await client.users.ensureWallet('user-123', {
1744
- * wallet_type: 'eoa',
1745
- * network: 'base-mainnet',
1746
- * });
1764
+ * // With specific network
1765
+ * const result = await client.users.ensureWallet('user-123', 'base-mainnet');
1747
1766
  * ```
1748
1767
  */
1749
- ensureWallet(externalId: string, options?: CreateWalletRequest): Promise<WalletCreationResult>;
1768
+ ensureWallet(externalId: string, network?: string): Promise<EnsureWalletResult>;
1750
1769
  /**
1751
1770
  * Update user attributes (convenience method) by external ID.
1752
1771
  * Merges the provided attributes into the existing attributes object.
package/dist/index.js CHANGED
@@ -1248,44 +1248,57 @@ var EndUsersClient = class {
1248
1248
  return this.http.post(`/end-users/by-external/${encodeURIComponent(externalId)}/register-wallet`, request);
1249
1249
  }
1250
1250
  /**
1251
- * Ensure a user has a wallet, creating one if they don't.
1251
+ * Ensure a user has dual wallets (EOA + Smart Account), creating them if they don't exist.
1252
1252
  *
1253
- * This is the recommended way for frontend devs to guarantee a wallet
1254
- * exists before performing any wallet-dependent operation (e.g. attestation,
1253
+ * This is the recommended way for frontend devs to guarantee wallets exist
1254
+ * before performing any wallet-dependent operation (e.g. attestation,
1255
1255
  * on-chain claims, token transfers).
1256
1256
  *
1257
- * If the user already has a wallet, returns immediately with the existing
1258
- * address. If not, creates a CDP wallet with the specified options.
1257
+ * If the user already has both wallet types, returns them immediately.
1258
+ * If not, creates a dual wallet pair (EOA asset wallet + Smart Account
1259
+ * for gasless transactions) via the CDP SDK.
1259
1260
  *
1260
1261
  * @param externalId - The user's external ID
1261
- * @param options - Wallet creation options (only used if a new wallet is created)
1262
- * @returns Wallet result with address and creation status
1262
+ * @param network - Network to create wallets on (default: 'base-sepolia')
1263
+ * @returns EnsureWalletResult with both wallets and whether they were newly created
1263
1264
  *
1264
1265
  * @example
1265
1266
  * ```typescript
1266
1267
  * // One-liner before any wallet-dependent operation
1267
- * const wallet = await client.users.ensureWallet('user-123');
1268
- * console.log(wallet.wallet_address); // '0xabc...'
1268
+ * const result = await client.users.ensureWallet('user-123');
1269
+ * console.log(result.asset_wallet.address); // '0xabc...'
1270
+ * console.log(result.smart_wallet.address); // '0xdef...'
1271
+ * console.log(result.created); // false if they already existed
1269
1272
  *
1270
- * // With options
1271
- * const wallet = await client.users.ensureWallet('user-123', {
1272
- * wallet_type: 'eoa',
1273
- * network: 'base-mainnet',
1274
- * });
1273
+ * // With specific network
1274
+ * const result = await client.users.ensureWallet('user-123', 'base-mainnet');
1275
1275
  * ```
1276
1276
  */
1277
- async ensureWallet(externalId, options = {}) {
1278
- const user = await this.get(externalId);
1279
- if (user.wallet_address) {
1280
- return {
1281
- success: true,
1282
- user_id: externalId,
1283
- wallet_address: user.wallet_address,
1284
- wallet_type: user.wallet_source ?? void 0,
1285
- source: "existing"
1286
- };
1277
+ async ensureWallet(externalId, network = "base-sepolia") {
1278
+ const existingWallets = await this.http.get(
1279
+ `/wallets/user/${encodeURIComponent(externalId)}`
1280
+ );
1281
+ if (existingWallets && existingWallets.length > 0) {
1282
+ const eoa = existingWallets.find((w) => w.wallet_type === "eoa");
1283
+ const smart = existingWallets.find((w) => w.wallet_type === "smart");
1284
+ if (eoa && smart) {
1285
+ return {
1286
+ user_id: externalId,
1287
+ asset_wallet: eoa,
1288
+ smart_wallet: smart,
1289
+ network: eoa.network,
1290
+ created: false
1291
+ };
1292
+ }
1287
1293
  }
1288
- return this.createWallet(externalId, options);
1294
+ const dual = await this.http.post("/wallets/dual", {
1295
+ user_id: externalId,
1296
+ network
1297
+ });
1298
+ return {
1299
+ ...dual,
1300
+ created: true
1301
+ };
1289
1302
  }
1290
1303
  /**
1291
1304
  * Update user attributes (convenience method) by external ID.
package/dist/index.mjs CHANGED
@@ -1194,44 +1194,57 @@ var EndUsersClient = class {
1194
1194
  return this.http.post(`/end-users/by-external/${encodeURIComponent(externalId)}/register-wallet`, request);
1195
1195
  }
1196
1196
  /**
1197
- * Ensure a user has a wallet, creating one if they don't.
1197
+ * Ensure a user has dual wallets (EOA + Smart Account), creating them if they don't exist.
1198
1198
  *
1199
- * This is the recommended way for frontend devs to guarantee a wallet
1200
- * exists before performing any wallet-dependent operation (e.g. attestation,
1199
+ * This is the recommended way for frontend devs to guarantee wallets exist
1200
+ * before performing any wallet-dependent operation (e.g. attestation,
1201
1201
  * on-chain claims, token transfers).
1202
1202
  *
1203
- * If the user already has a wallet, returns immediately with the existing
1204
- * address. If not, creates a CDP wallet with the specified options.
1203
+ * If the user already has both wallet types, returns them immediately.
1204
+ * If not, creates a dual wallet pair (EOA asset wallet + Smart Account
1205
+ * for gasless transactions) via the CDP SDK.
1205
1206
  *
1206
1207
  * @param externalId - The user's external ID
1207
- * @param options - Wallet creation options (only used if a new wallet is created)
1208
- * @returns Wallet result with address and creation status
1208
+ * @param network - Network to create wallets on (default: 'base-sepolia')
1209
+ * @returns EnsureWalletResult with both wallets and whether they were newly created
1209
1210
  *
1210
1211
  * @example
1211
1212
  * ```typescript
1212
1213
  * // One-liner before any wallet-dependent operation
1213
- * const wallet = await client.users.ensureWallet('user-123');
1214
- * console.log(wallet.wallet_address); // '0xabc...'
1214
+ * const result = await client.users.ensureWallet('user-123');
1215
+ * console.log(result.asset_wallet.address); // '0xabc...'
1216
+ * console.log(result.smart_wallet.address); // '0xdef...'
1217
+ * console.log(result.created); // false if they already existed
1215
1218
  *
1216
- * // With options
1217
- * const wallet = await client.users.ensureWallet('user-123', {
1218
- * wallet_type: 'eoa',
1219
- * network: 'base-mainnet',
1220
- * });
1219
+ * // With specific network
1220
+ * const result = await client.users.ensureWallet('user-123', 'base-mainnet');
1221
1221
  * ```
1222
1222
  */
1223
- async ensureWallet(externalId, options = {}) {
1224
- const user = await this.get(externalId);
1225
- if (user.wallet_address) {
1226
- return {
1227
- success: true,
1228
- user_id: externalId,
1229
- wallet_address: user.wallet_address,
1230
- wallet_type: user.wallet_source ?? void 0,
1231
- source: "existing"
1232
- };
1223
+ async ensureWallet(externalId, network = "base-sepolia") {
1224
+ const existingWallets = await this.http.get(
1225
+ `/wallets/user/${encodeURIComponent(externalId)}`
1226
+ );
1227
+ if (existingWallets && existingWallets.length > 0) {
1228
+ const eoa = existingWallets.find((w) => w.wallet_type === "eoa");
1229
+ const smart = existingWallets.find((w) => w.wallet_type === "smart");
1230
+ if (eoa && smart) {
1231
+ return {
1232
+ user_id: externalId,
1233
+ asset_wallet: eoa,
1234
+ smart_wallet: smart,
1235
+ network: eoa.network,
1236
+ created: false
1237
+ };
1238
+ }
1233
1239
  }
1234
- return this.createWallet(externalId, options);
1240
+ const dual = await this.http.post("/wallets/dual", {
1241
+ user_id: externalId,
1242
+ network
1243
+ });
1244
+ return {
1245
+ ...dual,
1246
+ created: true
1247
+ };
1235
1248
  }
1236
1249
  /**
1237
1250
  * Update user attributes (convenience method) by external ID.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proofchain/sdk",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "description": "Official JavaScript/TypeScript SDK for ProofChain - blockchain-anchored document attestation",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",