dop-wallet-v6 1.1.8 → 1.2.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.
@@ -1,5 +1,7 @@
1
1
  import { AddressData } from 'dop-engine-v5';
2
2
  import { DopWalletInfo } from 'dop-sharedmodel-v5';
3
+ export declare const createWalletFromTransaction: (leaf: any, viewingPrivateKey: Uint8Array, chain: any, encryptionKey: string, mnemonic: string, index?: number) => Promise<any>;
4
+ export declare const createUserWalletWithID: (encryptionKey: string, id: string, leaf: any, viewingPrivateKey: Uint8Array, chain: any) => Promise<any>;
3
5
  export declare const createDopWallet: (encryptionKey: string, mnemonic: string, creationBlockNumbers: Optional<MapType<number>>) => Promise<DopWalletInfo>;
4
6
  export declare const createViewOnlyDopWallet: (encryptionKey: string, shareableViewingKey: string, creationBlockNumbers: Optional<MapType<number>>) => Promise<DopWalletInfo>;
5
7
  export declare const loadWalletByID: (encryptionKey: string, dopWalletID: string, isViewOnlyWallet: boolean) => Promise<DopWalletInfo>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWalletShareableViewingKey = exports.getDopAddress = exports.validateEthAddress = exports.assertValidEthAddress = exports.validateDopAddress = exports.assertValidDopAddress = exports.signWithWalletViewingKey = exports.getDopWalletPrivateViewingKey = exports.getDopWalletAddressData = exports.getWalletMnemonic = exports.deleteWalletByID = exports.unloadWalletByID = exports.loadWalletByID = exports.createViewOnlyDopWallet = exports.createDopWallet = void 0;
3
+ exports.getWalletShareableViewingKey = exports.getDopAddress = exports.validateEthAddress = exports.assertValidEthAddress = exports.validateDopAddress = exports.assertValidDopAddress = exports.signWithWalletViewingKey = exports.getDopWalletPrivateViewingKey = exports.getDopWalletAddressData = exports.getWalletMnemonic = exports.deleteWalletByID = exports.unloadWalletByID = exports.loadWalletByID = exports.createViewOnlyDopWallet = exports.createDopWallet = exports.createUserWalletWithID = exports.createWalletFromTransaction = void 0;
4
4
  const dop_engine_v5_1 = require("dop-engine-v5");
5
5
  const dop_sharedmodel_v5_1 = require("dop-sharedmodel-v5");
6
6
  const engine_1 = require("../core/engine");
@@ -48,6 +48,20 @@ const loadExistingWallet = async (encryptionKey, dopWalletID, isViewOnlyWallet)
48
48
  subscribeToBalanceEvents(wallet);
49
49
  return infoForWallet(wallet);
50
50
  };
51
+ // here
52
+ const createWalletFromTransaction = async (leaf, viewingPrivateKey, chain, encryptionKey, mnemonic, index = 0) => {
53
+ const engine = (0, engine_1.getEngine)();
54
+ const res = engine.createUserWalletFromTransaction(leaf, viewingPrivateKey, chain, encryptionKey, mnemonic, index);
55
+ return res;
56
+ };
57
+ exports.createWalletFromTransaction = createWalletFromTransaction;
58
+ // here
59
+ const createUserWalletWithID = async (encryptionKey, id, leaf, viewingPrivateKey, chain) => {
60
+ const engine = (0, engine_1.getEngine)();
61
+ const res = engine.createUserWalletWithID(encryptionKey, id, leaf, viewingPrivateKey, chain);
62
+ return res;
63
+ };
64
+ exports.createUserWalletWithID = createUserWalletWithID;
51
65
  const createWallet = async (encryptionKey, mnemonic, creationBlockNumbers) => {
52
66
  const formattedCreationBlockNumbers = formatCreationBlockNumbers(creationBlockNumbers);
53
67
  const engine = (0, engine_1.getEngine)();
@@ -62,6 +76,7 @@ const createViewOnlyWallet = async (encryptionKey, shareableViewingKey, creation
62
76
  subscribeToBalanceEvents(wallet);
63
77
  return infoForWallet(wallet);
64
78
  };
79
+ // here
65
80
  const createDopWallet = async (encryptionKey, mnemonic, creationBlockNumbers) => {
66
81
  try {
67
82
  return await createWallet(encryptionKey, mnemonic, creationBlockNumbers);
@@ -1 +1 @@
1
- {"version":3,"file":"wallets.js","sourceRoot":"","sources":["../../../../src/services/dop/wallets/wallets.ts"],"names":[],"mappings":";;;AAAA,iDAUuB;AACvB,2DAK4B;AAC5B,2CAAwD;AACxD,qDAAoD;AACpD,gDAA8D;AAC9D,mCAAoC;AAEpC,MAAM,wBAAwB,GAAG,CAAC,M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,\n hexlify,\n hexStringToBytes,\n} from 'dop-engine-v5';\nimport {\n DopWalletInfo,\n NetworkName,\n NETWORK_CONFIG,\n isDefined,\n} from 'dop-sharedmodel-v5';\nimport { getEngine, walletForID } from '../core/engine';\nimport { onBalancesUpdate } from './balance-update';\nimport { reportAndSanitizeError } from '../../../utils/error';\nimport { getAddress } from 'ethers';\n\nconst subscribeToBalanceEvents = (wallet: AbstractWallet) => {\n wallet.on(\n EngineEvent.WalletScanComplete,\n ({ chain }: WalletScannedEventData) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n onBalancesUpdate(wallet, chain);\n },\n );\n};\n\nconst addressForWallet = (wallet: AbstractWallet): string => {\n return wallet.getAddress();\n};\n\nconst infoForWallet = (wallet: AbstractWallet): DopWalletInfo => {\n const dopAddress = addressForWallet(wallet);\n return {\n id: wallet.id,\n dopAddress,\n };\n};\n\nconst getExistingWallet = (\n dopWalletID: string,\n): Optional<AbstractWallet> => {\n try {\n const existingWallet = walletForID(dopWalletID);\n return existingWallet;\n } catch (_err) {\n return undefined;\n }\n};\n\nconst loadExistingWallet = async (\n encryptionKey: string,\n dopWalletID: string,\n isViewOnlyWallet: boolean,\n): Promise<DopWalletInfo> => {\n const existingWallet = getExistingWallet(dopWalletID);\n if (existingWallet) {\n return infoForWallet(existingWallet);\n }\n const engine = getEngine();\n let wallet: AbstractWallet;\n\n if (isViewOnlyWallet) {\n wallet = await engine.loadExistingViewOnlyWallet(\n encryptionKey,\n dopWalletID,\n );\n } else {\n wallet = await engine.loadExistingWallet(encryptionKey, dopWalletID);\n }\n\n subscribeToBalanceEvents(wallet);\n return infoForWallet(wallet);\n};\n\nconst createWallet = async (\n encryptionKey: string,\n mnemonic: string,\n creationBlockNumbers: Optional<MapType<number>>,\n): Promise<DopWalletInfo> => {\n const formattedCreationBlockNumbers =\n formatCreationBlockNumbers(creationBlockNumbers);\n\n const engine = getEngine();\n const wallet = await engine.createWalletFromMnemonic(\n encryptionKey,\n mnemonic,\n 0,\n formattedCreationBlockNumbers,\n );\n subscribeToBalanceEvents(wallet);\n return infoForWallet(wallet);\n};\n\nconst createViewOnlyWallet = async (\n encryptionKey: string,\n shareableViewingKey: string,\n creationBlockNumbers: Optional<MapType<number>>,\n): Promise<DopWalletInfo> => {\n const formattedCreationBlockNumbers =\n formatCreationBlockNumbers(creationBlockNumbers);\n\n const engine = getEngine();\n const wallet = await engine.createViewOnlyWalletFromShareableViewingKey(\n encryptionKey,\n shareableViewingKey,\n formattedCreationBlockNumbers,\n );\n subscribeToBalanceEvents(wallet);\n return infoForWallet(wallet);\n};\n\nexport const createDopWallet = async (\n encryptionKey: string,\n mnemonic: string,\n creationBlockNumbers: Optional<MapType<number>>,\n): Promise<DopWalletInfo> => {\n try {\n return await createWallet(encryptionKey, mnemonic, creationBlockNumbers);\n } catch (err) {\n throw reportAndSanitizeError(createDopWallet.name, err);\n }\n};\n\nexport const createViewOnlyDopWallet = async (\n encryptionKey: string,\n shareableViewingKey: string,\n creationBlockNumbers: Optional<MapType<number>>,\n): Promise<DopWalletInfo> => {\n try {\n return await createViewOnlyWallet(\n encryptionKey,\n shareableViewingKey,\n creationBlockNumbers,\n );\n } catch (err) {\n throw reportAndSanitizeError(createViewOnlyDopWallet.name, err);\n }\n};\n\nexport const loadWalletByID = async (\n encryptionKey: string,\n dopWalletID: string,\n isViewOnlyWallet: boolean,\n): Promise<DopWalletInfo> => {\n try {\n return await loadExistingWallet(\n encryptionKey,\n dopWalletID,\n isViewOnlyWallet,\n );\n } catch (err) {\n const sanitizedError = reportAndSanitizeError(loadWalletByID.name, err);\n throw new Error(`Could not load DOP wallet: ${sanitizedError.message}`);\n }\n};\n\nexport const unloadWalletByID = (dopWalletID: string): void => {\n try {\n const engine = getEngine();\n engine.unloadWallet(dopWalletID);\n } catch (err) {\n throw new Error('Could not unload DOP wallet.');\n }\n};\n\nexport const deleteWalletByID = async (\n dopWalletID: string,\n): Promise<void> => {\n try {\n const engine = getEngine();\n await engine.deleteWallet(dopWalletID);\n } catch (err) {\n throw new Error('Could not delete DOP wallet.');\n }\n};\n\nexport const getWalletMnemonic = async (\n encryptionKey: string,\n dopWalletID: string,\n) => {\n const { db } = getEngine();\n // Reload wallet to ensure that encryption key is valid.\n const walletData = (await DopWallet.getEncryptedData(\n db,\n encryptionKey,\n dopWalletID,\n )) as WalletData;\n\n if (!walletData.mnemonic) {\n throw new Error('No mnemonic for wallet.');\n }\n return walletData.mnemonic;\n};\n\nexport const getDopWalletAddressData = (address: string): AddressData => {\n assertValidDopAddress(address);\n return DopEngine.decodeAddress(address);\n};\n\nexport const getDopWalletPrivateViewingKey = (\n dopWalletID: string,\n): Uint8Array => {\n const wallet = walletForID(dopWalletID);\n return wallet.getViewingKeyPair().privateKey;\n};\n\nexport const signWithWalletViewingKey = async (\n dopWalletID: string,\n message: string,\n): Promise<string> => {\n const wallet = walletForID(dopWalletID);\n const signature = await wallet.signWithViewingKey(hexStringToBytes(message));\n return hexlify(signature);\n};\n\nexport const assertValidDopAddress = (address: string): void => {\n if (!validateDopAddress(address)) {\n throw new Error('Invalid DOP address.');\n }\n};\n\nexport const validateDopAddress = (address: string): boolean => {\n try {\n return DopEngine.decodeAddress(address) != null;\n } catch (err) {\n return false;\n }\n};\n\nexport const assertValidEthAddress = (address: string) => {\n if (!validateEthAddress(address)) {\n throw new Error('Invalid wallet address.');\n }\n};\n\nexport const validateEthAddress = (address: string): boolean => {\n try {\n getAddress(address);\n return true;\n } catch (err) {\n return false;\n }\n};\n\nexport const getDopAddress = (\n dopWalletID: string,\n): Optional<string> => {\n try {\n const wallet = walletForID(dopWalletID);\n return wallet.getAddress();\n } catch (err) {\n reportAndSanitizeError(getDopAddress.name, err);\n return undefined;\n }\n};\n\nexport const getWalletShareableViewingKey = async (\n dopWalletID: string,\n): Promise<Optional<string>> => {\n try {\n const wallet = walletForID(dopWalletID);\n return wallet.generateShareableViewingKey();\n } catch (err) {\n reportAndSanitizeError(getWalletShareableViewingKey.name, err);\n return undefined;\n }\n};\n\nconst formatCreationBlockNumbers = (\n creationBlockNumbers: Optional<MapType<number>>,\n): Optional<number[][]> => {\n // Format creationBlockNumbers from client side { <NetworkName>: <BlockNumber> } map to dop-engine's number[][] type\n if (!creationBlockNumbers) return;\n\n const formattedCreationBlockNumbers: number[][] = [];\n const networksNames = Object.keys(creationBlockNumbers) as NetworkName[];\n\n for (const networkName of networksNames) {\n const network = NETWORK_CONFIG[networkName];\n\n const blockNumber = creationBlockNumbers[networkName];\n if (!isDefined(blockNumber)) {\n continue;\n }\n\n formattedCreationBlockNumbers[network.chain.type] ??= [];\n formattedCreationBlockNumbers[network.chain.type][network.chain.id] =\n blockNumber;\n }\n\n return formattedCreationBlockNumbers;\n};\n"]}
1
+ {"version":3,"file":"wallets.js","sourceRoot":"","sources":["../../../../src/services/dop/wallets/wallets.ts"],"names":[],"mappings":";;;AAAA,iDAUuB;AACvB,2DAK4B;AAC5B,2CAAwD;AACxD,qDAAoD;AACpD,gDAA8D;AAC9D,mCAAoC;AAEpC,MAAM,wBAAwB,GAAG,CAAC,MAAsB,EAAE,EAAE;IAC1D,MAAM,CAAC,EAAE,CACP,2BAAW,CAAC,kBAAkB,EAC9B,CAAC,EAAE,KAAK,EAA0B,EAAE,EAAE;QACpC,mEAAmE;QACnE,IAAA,iCAAgB,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAClC,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,MAAsB,EAAU,EAAE;IAC1D,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;AAC7B,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,MAAsB,EAAiB,EAAE;IAC9D,MAAM,UAAU,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CACxB,WAAmB,EACO,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AAC,KAAK,CAAC,EAAE,CAAC;YACjE,WAAW,CAAC;KACf;IAED,OAAO,6BAA6B,CAAC;AACvC,CAAC,CAAC","sourcesContent":["import {\n DopWallet,\n EngineEvent,\n WalletScannedEventData,\n AbstractWallet,\n WalletData,\n AddressData,\n DopEngine,\n hexlify,\n hexStringToBytes,\n} from 'dop-engine-v5';\nimport {\n DopWalletInfo,\n NetworkName,\n NETWORK_CONFIG,\n isDefined,\n} from 'dop-sharedmodel-v5';\nimport { getEngine, walletForID } from '../core/engine';\nimport { onBalancesUpdate } from './balance-update';\nimport { reportAndSanitizeError } from '../../../utils/error';\nimport { getAddress } from 'ethers';\n\nconst subscribeToBalanceEvents = (wallet: AbstractWallet) => {\n wallet.on(\n EngineEvent.WalletScanComplete,\n ({ chain }: WalletScannedEventData) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n onBalancesUpdate(wallet, chain);\n },\n );\n};\n\nconst addressForWallet = (wallet: AbstractWallet): string => {\n return wallet.getAddress();\n};\n\nconst infoForWallet = (wallet: AbstractWallet): DopWalletInfo => {\n const dopAddress = addressForWallet(wallet);\n return {\n id: wallet.id,\n dopAddress,\n };\n};\n\nconst getExistingWallet = (\n dopWalletID: string,\n): Optional<AbstractWallet> => {\n try {\n const existingWallet = walletForID(dopWalletID);\n return existingWallet;\n } catch (_err) {\n return undefined;\n }\n};\n\nconst loadExistingWallet = async (\n encryptionKey: string,\n dopWalletID: string,\n isViewOnlyWallet: boolean,\n): Promise<DopWalletInfo> => {\n const existingWallet = getExistingWallet(dopWalletID);\n if (existingWallet) {\n return infoForWallet(existingWallet);\n }\n const engine = getEngine();\n let wallet: AbstractWallet;\n\n if (isViewOnlyWallet) {\n wallet = await engine.loadExistingViewOnlyWallet(\n encryptionKey,\n dopWalletID,\n );\n } else {\n wallet = await engine.loadExistingWallet(encryptionKey, dopWalletID);\n }\n\n subscribeToBalanceEvents(wallet);\n return infoForWallet(wallet);\n};\n// here\nexport const createWalletFromTransaction = async (\n leaf: any,\n viewingPrivateKey: Uint8Array,\n chain: any,\n encryptionKey: string,\n mnemonic: string,\n index: number = 0,\n): Promise<any> => {\n\n const engine = getEngine();\n const res = engine.createUserWalletFromTransaction(leaf, viewingPrivateKey, chain, encryptionKey, mnemonic, index);\n return res;\n};\n\n// here\nexport const createUserWalletWithID = async (\n encryptionKey: string,\n id: string,\n leaf: any,\n viewingPrivateKey: Uint8Array,\n chain: any\n): Promise<any> => {\n\n const engine = getEngine();\n const res = engine.createUserWalletWithID(\n encryptionKey,\n id,\n leaf,\n viewingPrivateKey,\n chain\n );\n return res;\n};\n\n\nconst createWallet = async (\n encryptionKey: string,\n mnemonic: string,\n creationBlockNumbers: Optional<MapType<number>>,\n): Promise<DopWalletInfo> => {\n const formattedCreationBlockNumbers =\n formatCreationBlockNumbers(creationBlockNumbers);\n\n const engine = getEngine();\n\n const wallet = await engine.createWalletFromMnemonic(\n encryptionKey,\n mnemonic,\n 0,\n formattedCreationBlockNumbers,\n );\n subscribeToBalanceEvents(wallet);\n return infoForWallet(wallet);\n};\n\nconst createViewOnlyWallet = async (\n encryptionKey: string,\n shareableViewingKey: string,\n creationBlockNumbers: Optional<MapType<number>>,\n): Promise<DopWalletInfo> => {\n const formattedCreationBlockNumbers =\n formatCreationBlockNumbers(creationBlockNumbers);\n\n const engine = getEngine();\n const wallet = await engine.createViewOnlyWalletFromShareableViewingKey(\n encryptionKey,\n shareableViewingKey,\n formattedCreationBlockNumbers,\n );\n subscribeToBalanceEvents(wallet);\n return infoForWallet(wallet);\n};\n// here \nexport const createDopWallet = async (\n encryptionKey: string,\n mnemonic: string,\n creationBlockNumbers: Optional<MapType<number>>,\n): Promise<DopWalletInfo> => {\n try {\n\n return await createWallet(encryptionKey, mnemonic, creationBlockNumbers);\n } catch (err) {\n throw reportAndSanitizeError(createDopWallet.name, err);\n }\n};\n\nexport const createViewOnlyDopWallet = async (\n encryptionKey: string,\n shareableViewingKey: string,\n creationBlockNumbers: Optional<MapType<number>>,\n): Promise<DopWalletInfo> => {\n try {\n return await createViewOnlyWallet(\n encryptionKey,\n shareableViewingKey,\n creationBlockNumbers,\n );\n } catch (err) {\n throw reportAndSanitizeError(createViewOnlyDopWallet.name, err);\n }\n};\n\nexport const loadWalletByID = async (\n encryptionKey: string,\n dopWalletID: string,\n isViewOnlyWallet: boolean,\n): Promise<DopWalletInfo> => {\n try {\n return await loadExistingWallet(\n encryptionKey,\n dopWalletID,\n isViewOnlyWallet,\n );\n } catch (err) {\n const sanitizedError = reportAndSanitizeError(loadWalletByID.name, err);\n throw new Error(`Could not load DOP wallet: ${sanitizedError.message}`);\n }\n};\n\nexport const unloadWalletByID = (dopWalletID: string): void => {\n try {\n const engine = getEngine();\n engine.unloadWallet(dopWalletID);\n } catch (err) {\n throw new Error('Could not unload DOP wallet.');\n }\n};\n\nexport const deleteWalletByID = async (\n dopWalletID: string,\n): Promise<void> => {\n try {\n const engine = getEngine();\n await engine.deleteWallet(dopWalletID);\n } catch (err) {\n throw new Error('Could not delete DOP wallet.');\n }\n};\n\nexport const getWalletMnemonic = async (\n encryptionKey: string,\n dopWalletID: string,\n) => {\n const { db } = getEngine();\n // Reload wallet to ensure that encryption key is valid.\n const walletData = (await DopWallet.getEncryptedData(\n db,\n encryptionKey,\n dopWalletID,\n )) as WalletData;\n\n if (!walletData.mnemonic) {\n throw new Error('No mnemonic for wallet.');\n }\n return walletData.mnemonic;\n};\n\nexport const getDopWalletAddressData = (address: string): AddressData => {\n assertValidDopAddress(address);\n return DopEngine.decodeAddress(address);\n};\n\nexport const getDopWalletPrivateViewingKey = (\n dopWalletID: string,\n): Uint8Array => {\n const wallet = walletForID(dopWalletID);\n return wallet.getViewingKeyPair().privateKey;\n};\n\nexport const signWithWalletViewingKey = async (\n dopWalletID: string,\n message: string,\n): Promise<string> => {\n const wallet = walletForID(dopWalletID);\n const signature = await wallet.signWithViewingKey(hexStringToBytes(message));\n return hexlify(signature);\n};\n\n\n\nexport const assertValidDopAddress = (address: string): void => {\n if (!validateDopAddress(address)) {\n throw new Error('Invalid DOP address.');\n }\n};\n\nexport const validateDopAddress = (address: string): boolean => {\n try {\n return DopEngine.decodeAddress(address) != null;\n } catch (err) {\n return false;\n }\n};\n\nexport const assertValidEthAddress = (address: string) => {\n if (!validateEthAddress(address)) {\n throw new Error('Invalid wallet address.');\n }\n};\n\nexport const validateEthAddress = (address: string): boolean => {\n try {\n getAddress(address);\n return true;\n } catch (err) {\n return false;\n }\n};\n\nexport const getDopAddress = (\n dopWalletID: string,\n): Optional<string> => {\n try {\n const wallet = walletForID(dopWalletID);\n return wallet.getAddress();\n } catch (err) {\n reportAndSanitizeError(getDopAddress.name, err);\n return undefined;\n }\n};\n\nexport const getWalletShareableViewingKey = async (\n dopWalletID: string,\n): Promise<Optional<string>> => {\n try {\n const wallet = walletForID(dopWalletID);\n return wallet.generateShareableViewingKey();\n } catch (err) {\n reportAndSanitizeError(getWalletShareableViewingKey.name, err);\n return undefined;\n }\n};\n\nconst formatCreationBlockNumbers = (\n creationBlockNumbers: Optional<MapType<number>>,\n): Optional<number[][]> => {\n // Format creationBlockNumbers from client side { <NetworkName>: <BlockNumber> } map to dop-engine's number[][] type\n if (!creationBlockNumbers) return;\n\n const formattedCreationBlockNumbers: number[][] = [];\n const networksNames = Object.keys(creationBlockNumbers) as NetworkName[];\n\n for (const networkName of networksNames) {\n const network = NETWORK_CONFIG[networkName];\n\n const blockNumber = creationBlockNumbers[networkName];\n if (!isDefined(blockNumber)) {\n continue;\n }\n\n formattedCreationBlockNumbers[network.chain.type] ??= [];\n formattedCreationBlockNumbers[network.chain.type][network.chain.id] =\n blockNumber;\n }\n\n return formattedCreationBlockNumbers;\n};\n"]}
@@ -14,11 +14,13 @@ const getGasEstimate = async (networkName, transaction, fromWalletAddress, sendW
14
14
  from: fromWalletAddress,
15
15
  type: evmGasType,
16
16
  };
17
+ console.log("estimateGasTransactionRequest:::1", estimateGasTransactionRequest);
17
18
  if (shouldRemoveGasLimitForL2GasEstimate(networkName)) {
18
19
  delete estimateGasTransactionRequest.gasLimit;
19
20
  }
20
21
  try {
21
22
  const gasEstimate = await estimateGas(networkName, estimateGasTransactionRequest, isCrossContractCall);
23
+ console.log("before gasEstimate", gasEstimate);
22
24
  return gasEstimate;
23
25
  }
24
26
  catch (err) {
@@ -26,13 +28,21 @@ const getGasEstimate = async (networkName, transaction, fromWalletAddress, sendW
26
28
  }
27
29
  };
28
30
  exports.getGasEstimate = getGasEstimate;
31
+ 0xe4899c1300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000100000000000000000000000000261705b09939a2271eb98b782fb02435c02beeda000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024e9a059a3000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000000000000000000000261705b09939a2271eb98b782fb02435c02beeda000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000184bf8d1c5b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000082389495bb548e00e901f8ac82e9761152898834000000000000000000000000000000000000000000000000000000000000000120cd37ba9a49df5deeddb3f6355431c55d21b8aeaa6a2a91dddd12378bd76ebc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf12700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc10000504b0dc14f036567d6deb04c09480a1f36c4682faa260c0bf15ff98e66714d252592874afaf1beb2866a003fd1677caaf7b128cbd075709aa8d494dbf482c04d3958b0826a15613654d15cce9a622b2dc1553ead6243f9c77fbc6f15d01c985f8026f7ae910774362b20aa14a3e4f6bb8e8762038d58f4094576bd9ffe92c87200000000000000000000000000000000000000000000000000000000;
29
32
  const estimateGas = (networkName, transaction, isCrossContractCall) => {
30
33
  const provider = (0, dop_1.getFallbackProviderForNetwork)(networkName);
34
+ console.log("before isCrossContractCall", isCrossContractCall);
31
35
  if (isCrossContractCall) {
32
36
  // Includes custom error handler for relay-adapt transactions.
33
37
  return dop_engine_v5_1.RelayAdaptContract.estimateGasWithErrorHandler(provider, transaction);
34
38
  }
35
- return provider.estimateGas(transaction);
39
+ try {
40
+ return provider.estimateGas(transaction);
41
+ }
42
+ catch (e) {
43
+ console.log("before error:::", e);
44
+ return new Promise(resolve => resolve);
45
+ }
36
46
  };
37
47
  /**
38
48
  * Gas estimates can fail for relay-adapt transactions on L2s like Arbitrum.
@@ -64,10 +74,12 @@ const gasEstimateResponse = (gasEstimate, relayerFeeCommitment, isGasEstimateWit
64
74
  const gasEstimateWithDummyProofVariance = isGasEstimateWithDummyProof
65
75
  ? gasEstimate + BigInt(dop_engine_v5_1.GAS_ESTIMATE_VARIANCE_DUMMY_TO_ACTUAL_TRANSACTION)
66
76
  : gasEstimate;
77
+ console.log("gasEstimateWithDummyProofVariance:::2", gasEstimateWithDummyProofVariance);
67
78
  const response = {
68
79
  gasEstimate: gasEstimateWithDummyProofVariance,
69
80
  relayerFeeCommitment,
70
81
  };
82
+ console.log("before DopTransactionGasEstimateResponse return:::1");
71
83
  return response;
72
84
  };
73
85
  exports.gasEstimateResponse = gasEstimateResponse;
@@ -1 +1 @@
1
- {"version":3,"file":"tx-gas-details.js","sourceRoot":"","sources":["../../../src/services/transactions/tx-gas-details.ts"],"names":[],"mappings":";;;AAAA,2DAQ4B;AAC5B,gCAAuD;AACvD,6CAA2D;AAC3D,iDAGuB;AAGhB,MAAM,cAAc,GAAG,KAAK,EACjC,WAAwB,EACxB,WAAgC,EAChC,iBAAyB,EACzB,oBAA6B,EAC7B,mBAA4B,EACX,EAAE;IACnB,MAAM,UAAU,GAAG,IAAA,gDAA2B,EAC5C,WAAW,EACX,oBAAoB,CACrB,CAAC;IAEF,0DAA0D;IAC1D,iFAAiF;IACjF,MAAM,6B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U,CAAC,UAAU,CAAC;IAEzC,QAAQ,UAAU,CAAC,UAAU,EAAE;QAC7B,KAAK,+BAAU,CAAC,KAAK,CAAC,CAAC;YACrB,6CAA6C;YAC7C,WAAW,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC;YAC3C,6CAA6C;YAC7C,OAAO,WAAW,CAAC,UAAU,CAAC;YAC9B,MAAM;SACP;QACD,KAAK,+BAAU,CAAC,KAAK,CAAC,CAAC;YACrB,6CAA6C;YAC7C,WAAW,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC;YAC3C,MAAM;SACP;QACD,KAAK,+BAAU,CAAC,KAAK,CAAC,CAAC;YACrB,6CAA6C;YAC7C,WAAW,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;YACnD,6CAA6C;YAC7C,WAAW,CAAC,oBAAoB,GAAG,UAAU,CAAC,oBAAoB,CAAC;YACnE,MAAM;SACP;KACF;AACH,CAAC,CAAC;AA/CW,QAAA,2BAA2B,+BA+CtC","sourcesContent":["import {\n DopTransactionGasEstimateResponse,\n EVMGasType,\n calculateGasLimit,\n NetworkName,\n getEVMGasTypeForTransaction,\n CommitmentSummary,\n TransactionGasDetails,\n} from 'dop-sharedmodel-v5';\nimport { getFallbackProviderForNetwork } from '../dop';\nimport { reportAndSanitizeError } from '../../utils/error';\nimport {\n GAS_ESTIMATE_VARIANCE_DUMMY_TO_ACTUAL_TRANSACTION,\n RelayAdaptContract,\n} from 'dop-engine-v5';\nimport { ContractTransaction } from 'ethers';\n\nexport const getGasEstimate = async (\n networkName: NetworkName,\n transaction: ContractTransaction,\n fromWalletAddress: string,\n sendWithPublicWallet: boolean,\n isCrossContractCall: boolean,\n): Promise<bigint> => {\n const evmGasType = getEVMGasTypeForTransaction(\n networkName,\n sendWithPublicWallet,\n );\n\n // Add 'from' field, which is required, as a mock address.\n // Note that DEPOSIT needs a real address, as it checks the balance for transfer.\n const estimateGasTransactionRequest: ContractTransaction = {\n ...transaction,\n from: fromWalletAddress,\n type: evmGasType,\n };\n\n if (shouldRemoveGasLimitForL2GasEstimate(networkName)) {\n delete estimateGasTransactionRequest.gasLimit;\n }\n\n try {\n const gasEstimate = await estimateGas(\n networkName,\n estimateGasTransactionRequest,\n isCrossContractCall,\n );\n\n return gasEstimate;\n } catch (err) {\n throw reportAndSanitizeError(getGasEstimate.name, err);\n }\n};\n\nconst estimateGas = (\n networkName: NetworkName,\n transaction: ContractTransaction,\n isCrossContractCall: boolean,\n): Promise<bigint> => {\n const provider = getFallbackProviderForNetwork(networkName);\n\n if (isCrossContractCall) {\n // Includes custom error handler for relay-adapt transactions.\n return RelayAdaptContract.estimateGasWithErrorHandler(\n provider,\n transaction,\n );\n }\n return provider.estimateGas(transaction);\n};\n\n/**\n * Gas estimates can fail for relay-adapt transactions on L2s like Arbitrum.\n * This occurs on cross-contract calls (relay-adapt) which have a manual minimum gas limit set by Dop Engine.\n */\nconst shouldRemoveGasLimitForL2GasEstimate = (networkName: NetworkName) => {\n switch (networkName) {\n case NetworkName.Arbitrum:\n case NetworkName.ArbitrumGoerli:\n return true;\n case NetworkName.Xlayer:\n case NetworkName.XlayerTestnet:\n return true;\n case NetworkName.Dop:\n throw new Error('Invalid network for transaction');\n case NetworkName.Ethereum:\n case NetworkName.BNBChain:\n case NetworkName.Polygon:\n case NetworkName.EthereumRopsten_DEPRECATED:\n case NetworkName.EthereumGoerli:\n case NetworkName.PolygonMumbai:\n case NetworkName.Hardhat:\n return false;\n }\n};\n\nexport const gasEstimateResponse = (\n gasEstimate: bigint,\n relayerFeeCommitment: Optional<CommitmentSummary>,\n isGasEstimateWithDummyProof: boolean,\n): DopTransactionGasEstimateResponse => {\n // TODO: This variance will be different on L2s.\n // However, it's small enough that it shouldn't matter very much.\n const gasEstimateWithDummyProofVariance = isGasEstimateWithDummyProof\n ? gasEstimate + BigInt(GAS_ESTIMATE_VARIANCE_DUMMY_TO_ACTUAL_TRANSACTION)\n : gasEstimate;\n\n\n\n const response: DopTransactionGasEstimateResponse = {\n gasEstimate: gasEstimateWithDummyProofVariance,\n relayerFeeCommitment,\n };\n\n return response;\n};\n\nexport const setGasDetailsForTransaction = (\n networkName: NetworkName,\n transaction: ContractTransaction,\n gasDetails: TransactionGasDetails,\n sendWithPublicWallet: boolean,\n) => {\n const { gasEstimate } = gasDetails;\n\n // eslint-disable-next-line no-param-reassign\n transaction.gasLimit = calculateGasLimit(gasEstimate);\n\n const evmGasType = getEVMGasTypeForTransaction(\n networkName,\n sendWithPublicWallet,\n );\n\n if (gasDetails.evmGasType !== evmGasType) {\n const transactionType = sendWithPublicWallet ? 'self-signed' : 'Relayer';\n throw new Error(\n `Invalid evmGasType for ${networkName} (${transactionType}): expected Type${evmGasType}, received Type${gasDetails.evmGasType} in gasDetails. Retrieve appropriate gas type with getEVMGasTypeForTransaction (dop-sharedmodel).`,\n );\n }\n\n // eslint-disable-next-line no-param-reassign\n transaction.type = gasDetails.evmGasType;\n\n switch (gasDetails.evmGasType) {\n case EVMGasType.Type0: {\n // eslint-disable-next-line no-param-reassign\n transaction.gasPrice = gasDetails.gasPrice;\n // eslint-disable-next-line no-param-reassign\n delete transaction.accessList;\n break;\n }\n case EVMGasType.Type1: {\n // eslint-disable-next-line no-param-reassign\n transaction.gasPrice = gasDetails.gasPrice;\n break;\n }\n case EVMGasType.Type2: {\n // eslint-disable-next-line no-param-reassign\n transaction.maxFeePerGas = gasDetails.maxFeePerGas;\n // eslint-disable-next-line no-param-reassign\n transaction.maxPriorityFeePerGas = gasDetails.maxPriorityFeePerGas;\n break;\n }\n }\n};\n"]}
1
+ {"version":3,"file":"tx-gas-details.js","sourceRoot":"","sources":["../../../src/services/transactions/tx-gas-details.ts"],"names":[],"mappings":";;;AAAA,2DAQ4B;AAC5B,gCAAuD;AACvD,6CAA2D;AAC3D,iDAGuB;AAGhB,MAAM,cAAc,GAAG,KAAK,EACjC,WAAwB,EACxB,WAAgC,EAChC,iBAAyB,EACzB,oBAA6B,EAC7B,mBAA4B,E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ACH,CAAC,CAAC;AA/CW,QAAA,2BAA2B,+BA+CtC","sourcesContent":["import {\n DopTransactionGasEstimateResponse,\n EVMGasType,\n calculateGasLimit,\n NetworkName,\n getEVMGasTypeForTransaction,\n CommitmentSummary,\n TransactionGasDetails,\n} from 'dop-sharedmodel-v5';\nimport { getFallbackProviderForNetwork } from '../dop';\nimport { reportAndSanitizeError } from '../../utils/error';\nimport {\n GAS_ESTIMATE_VARIANCE_DUMMY_TO_ACTUAL_TRANSACTION,\n RelayAdaptContract,\n} from 'dop-engine-v5';\nimport { ContractTransaction } from 'ethers';\n\nexport const getGasEstimate = async (\n networkName: NetworkName,\n transaction: ContractTransaction,\n fromWalletAddress: string,\n sendWithPublicWallet: boolean,\n isCrossContractCall: boolean,\n): Promise<bigint> => {\n const evmGasType = getEVMGasTypeForTransaction(\n networkName,\n sendWithPublicWallet,\n );\n\n // Add 'from' field, which is required, as a mock address.\n // Note that DEPOSIT needs a real address, as it checks the balance for transfer.\n const estimateGasTransactionRequest: ContractTransaction = {\n ...transaction,\n from: fromWalletAddress,\n type: evmGasType,\n };\n console.log(\"estimateGasTransactionRequest:::1\", estimateGasTransactionRequest);\n\n\n if (shouldRemoveGasLimitForL2GasEstimate(networkName)) {\n delete estimateGasTransactionRequest.gasLimit;\n }\n\n try {\n const gasEstimate = await estimateGas(\n networkName,\n estimateGasTransactionRequest,\n isCrossContractCall,\n );\n console.log(\"before gasEstimate\", gasEstimate);\n\n return gasEstimate;\n } catch (err) {\n throw reportAndSanitizeError(getGasEstimate.name, err);\n }\n};\n\n0xe4899c1300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000100000000000000000000000000261705b09939a2271eb98b782fb02435c02beeda000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024e9a059a3000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000000000000000000000261705b09939a2271eb98b782fb02435c02beeda000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000184bf8d1c5b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000082389495bb548e00e901f8ac82e9761152898834000000000000000000000000000000000000000000000000000000000000000120cd37ba9a49df5deeddb3f6355431c55d21b8aeaa6a2a91dddd12378bd76ebc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf12700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc10000504b0dc14f036567d6deb04c09480a1f36c4682faa260c0bf15ff98e66714d252592874afaf1beb2866a003fd1677caaf7b128cbd075709aa8d494dbf482c04d3958b0826a15613654d15cce9a622b2dc1553ead6243f9c77fbc6f15d01c985f8026f7ae910774362b20aa14a3e4f6bb8e8762038d58f4094576bd9ffe92c87200000000000000000000000000000000000000000000000000000000\n\nconst estimateGas = (\n networkName: NetworkName,\n transaction: ContractTransaction,\n isCrossContractCall: boolean,\n): Promise<bigint> => {\n const provider = getFallbackProviderForNetwork(networkName);\n console.log(\"before isCrossContractCall\", isCrossContractCall);\n\n if (isCrossContractCall) {\n // Includes custom error handler for relay-adapt transactions.\n return RelayAdaptContract.estimateGasWithErrorHandler(\n provider,\n transaction,\n );\n }\n try{\n\n return provider.estimateGas(transaction);\n }catch(e){\n console.log(\"before error:::\", e)\n return new Promise(resolve => resolve)\n }\n};\n\n/**\n * Gas estimates can fail for relay-adapt transactions on L2s like Arbitrum.\n * This occurs on cross-contract calls (relay-adapt) which have a manual minimum gas limit set by Dop Engine.\n */\nconst shouldRemoveGasLimitForL2GasEstimate = (networkName: NetworkName) => {\n switch (networkName) {\n case NetworkName.Arbitrum:\n case NetworkName.ArbitrumGoerli:\n return true;\n case NetworkName.Xlayer:\n case NetworkName.XlayerTestnet:\n return true;\n case NetworkName.Dop:\n throw new Error('Invalid network for transaction');\n case NetworkName.Ethereum:\n case NetworkName.BNBChain:\n case NetworkName.Polygon:\n case NetworkName.EthereumRopsten_DEPRECATED:\n case NetworkName.EthereumGoerli:\n case NetworkName.PolygonMumbai:\n case NetworkName.Hardhat:\n return false;\n }\n};\n\nexport const gasEstimateResponse = (\n gasEstimate: bigint,\n relayerFeeCommitment: Optional<CommitmentSummary>,\n isGasEstimateWithDummyProof: boolean,\n): DopTransactionGasEstimateResponse => {\n // TODO: This variance will be different on L2s.\n // However, it's small enough that it shouldn't matter very much.\n const gasEstimateWithDummyProofVariance = isGasEstimateWithDummyProof\n ? gasEstimate + BigInt(GAS_ESTIMATE_VARIANCE_DUMMY_TO_ACTUAL_TRANSACTION)\n : gasEstimate;\n\n console.log(\"gasEstimateWithDummyProofVariance:::2\", gasEstimateWithDummyProofVariance);\n\n const response: DopTransactionGasEstimateResponse = {\n gasEstimate: gasEstimateWithDummyProofVariance,\n relayerFeeCommitment,\n };\n console.log(\"before DopTransactionGasEstimateResponse return:::1\");\n\n\n return response;\n};\n\nexport const setGasDetailsForTransaction = (\n networkName: NetworkName,\n transaction: ContractTransaction,\n gasDetails: TransactionGasDetails,\n sendWithPublicWallet: boolean,\n) => {\n const { gasEstimate } = gasDetails;\n\n // eslint-disable-next-line no-param-reassign\n transaction.gasLimit = calculateGasLimit(gasEstimate);\n\n const evmGasType = getEVMGasTypeForTransaction(\n networkName,\n sendWithPublicWallet,\n );\n\n if (gasDetails.evmGasType !== evmGasType) {\n const transactionType = sendWithPublicWallet ? 'self-signed' : 'Relayer';\n throw new Error(\n `Invalid evmGasType for ${networkName} (${transactionType}): expected Type${evmGasType}, received Type${gasDetails.evmGasType} in gasDetails. Retrieve appropriate gas type with getEVMGasTypeForTransaction (dop-sharedmodel).`,\n );\n }\n\n // eslint-disable-next-line no-param-reassign\n transaction.type = gasDetails.evmGasType;\n\n switch (gasDetails.evmGasType) {\n case EVMGasType.Type0: {\n // eslint-disable-next-line no-param-reassign\n transaction.gasPrice = gasDetails.gasPrice;\n // eslint-disable-next-line no-param-reassign\n delete transaction.accessList;\n break;\n }\n case EVMGasType.Type1: {\n // eslint-disable-next-line no-param-reassign\n transaction.gasPrice = gasDetails.gasPrice;\n break;\n }\n case EVMGasType.Type2: {\n // eslint-disable-next-line no-param-reassign\n transaction.maxFeePerGas = gasDetails.maxFeePerGas;\n // eslint-disable-next-line no-param-reassign\n transaction.maxPriorityFeePerGas = gasDetails.maxPriorityFeePerGas;\n break;\n }\n }\n};\n"]}
@@ -1,3 +1,3 @@
1
1
  import { DopPopulateTransactionResponse, DopTransactionGasEstimateResponse, DopERC20Amount, NetworkName, TransactionGasDetails } from 'dop-sharedmodel-v5';
2
- export declare const populateShieldBaseToken: (networkName: NetworkName, dopAddress: string, shieldPrivateKey: string, wrappedERC20Amount: DopERC20Amount, gasDetails?: TransactionGasDetails) => Promise<DopPopulateTransactionResponse>;
2
+ export declare const populateShieldBaseToken: (networkName: NetworkName, dopAddress: string, shieldPrivateKey: string, wrappedERC20Amount: DopERC20Amount, fromWalletAddress: string, gasDetails?: TransactionGasDetails) => Promise<DopPopulateTransactionResponse>;
3
3
  export declare const gasEstimateForShieldBaseToken: (networkName: NetworkName, dopAddress: string, shieldPrivateKey: string, wrappedERC20Amount: DopERC20Amount, fromWalletAddress: string) => Promise<DopTransactionGasEstimateResponse>;
@@ -7,7 +7,7 @@ const blocked_address_1 = require("../../utils/blocked-address");
7
7
  const dop_engine_v5_1 = require("dop-engine-v5");
8
8
  const dop_1 = require("../dop");
9
9
  const error_1 = require("../../utils/error");
10
- const generateShieldBaseTokenTransaction = async (networkName, dopAddress, shieldPrivateKey, wrappedERC20Amount) => {
10
+ const generateShieldBaseTokenTransaction = async (networkName, dopAddress, shieldPrivateKey, wrappedERC20Amount, fromWalletAddress) => {
11
11
  try {
12
12
  const relayAdaptContract = (0, providers_1.getRelayAdaptContractForNetwork)(networkName);
13
13
  const { masterPublicKey, viewingPublicKey } = dop_engine_v5_1.DopEngine.decodeAddress(dopAddress);
@@ -15,7 +15,8 @@ const generateShieldBaseTokenTransaction = async (networkName, dopAddress, shiel
15
15
  const { amount, tokenAddress } = wrappedERC20Amount;
16
16
  const shield = new dop_engine_v5_1.ShieldNoteERC20(masterPublicKey, random, amount, tokenAddress);
17
17
  const shieldRequest = await shield.serialize((0, dop_engine_v5_1.hexToBytes)(shieldPrivateKey), viewingPublicKey);
18
- const transaction = await relayAdaptContract.populateShieldBaseToken(shieldRequest);
18
+ console.log("before populateShieldBaseToken");
19
+ const transaction = await relayAdaptContract.populateShieldBaseToken(shieldRequest, fromWalletAddress);
19
20
  return transaction;
20
21
  }
21
22
  catch (err) {
@@ -23,10 +24,10 @@ const generateShieldBaseTokenTransaction = async (networkName, dopAddress, shiel
23
24
  throw sanitizedError;
24
25
  }
25
26
  };
26
- const populateShieldBaseToken = async (networkName, dopAddress, shieldPrivateKey, wrappedERC20Amount, gasDetails) => {
27
+ const populateShieldBaseToken = async (networkName, dopAddress, shieldPrivateKey, wrappedERC20Amount, fromWalletAddress, gasDetails) => {
27
28
  try {
28
29
  (0, dop_1.assertValidDopAddress)(dopAddress);
29
- const transaction = await generateShieldBaseTokenTransaction(networkName, dopAddress, shieldPrivateKey, wrappedERC20Amount);
30
+ const transaction = await generateShieldBaseTokenTransaction(networkName, dopAddress, shieldPrivateKey, wrappedERC20Amount, fromWalletAddress);
30
31
  if (gasDetails) {
31
32
  const sendWithPublicWallet = true;
32
33
  (0, tx_gas_details_1.setGasDetailsForTransaction)(networkName, transaction, gasDetails, sendWithPublicWallet);
@@ -44,7 +45,9 @@ const gasEstimateForShieldBaseToken = async (networkName, dopAddress, shieldPriv
44
45
  try {
45
46
  (0, dop_1.assertValidDopAddress)(dopAddress);
46
47
  (0, blocked_address_1.assertNotBlockedAddress)(fromWalletAddress);
47
- const transaction = await generateShieldBaseTokenTransaction(networkName, dopAddress, shieldPrivateKey, wrappedERC20Amount);
48
+ console.log("before generateShieldBaseTokenTransaction");
49
+ const transaction = await generateShieldBaseTokenTransaction(networkName, dopAddress, shieldPrivateKey, wrappedERC20Amount, fromWalletAddress);
50
+ console.log("before generateShieldBaseTokenTransaction2");
48
51
  const sendWithPublicWallet = true;
49
52
  const isGasEstimateWithDummyProof = false;
50
53
  return (0, tx_gas_details_1.gasEstimateResponse)(await (0, tx_gas_details_1.getGasEstimate)(networkName, transaction, fromWalletAddress, sendWithPublicWallet, false), undefined, // relayerFeeCommitment
@@ -1 +1 @@
1
- {"version":3,"file":"tx-shield-base-token.js","sourceRoot":"","sources":["../../../src/services/transactions/tx-shield-base-token.ts"],"names":[],"mappings":";;;AAOA,qDAAwE;AACxE,qDAI0B;AAC1B,iEAAsE;AACtE,iDAKuB;AACvB,gCAA+C;AAC/C,6CAA2D;AAG3D,MAAM,kCAAkC,GAAG,KAAK,EAC9C,WAAwB,EACxB,UAAkB,EAClB,gBAAwB,EACxB,kBAAkC,EACJ,EAAE;IAChC,IAAI;QACF,MAAM,kBAAkB,GAAG,IAAA,2CAA+B,EAAC,WAAW,CAAC,CAAC;QACxE,MAAM,EAAE,eAAe,EAAE,gBAAgB,EAAE,GACzC,yBAAS,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACtC,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,EAAE,CAAC,CAAC;QAE7B,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,kBAAkB,CAAC;QAEpD,MAAM,MAAM,GAAG,IAAI,+BAAe,CAChC,eAAe,EACf,MAAM,EACN,MAAM,EACN,YAAY,CACb,CAAC;QAEF,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,SAAS,CAC1C,IAAA,0BAAU,EAAC,gBAAgB,CAAC,EAC5B,gBAAgB,CACjB,CAAC;QAEF,MAAM,WAAW,GAAG,MAAM,kBAAkB,CAAC,uBAAuB,CAClE,aAAa,CACd,CAAC;QAEF,OAAO,WAAW,CAAC;KACpB;IAAC,OAAO,GAAG,EAAE;QACZ,M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oBAAoB,EACpB,KAAK,CACN,EACD,SAAS,EAAE,uBAAuB;QAClC,2BAA2B,CAC5B,CAAC;KACH;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAA,8BAAsB,EAAC,qCAA6B,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KACvE;AACH,CAAC,CAAC;AAlCW,QAAA,6BAA6B,iCAkCxC","sourcesContent":["import {\n DopPopulateTransactionResponse,\n DopTransactionGasEstimateResponse,\n DopERC20Amount,\n NetworkName,\n TransactionGasDetails,\n} from 'dop-sharedmodel-v5';\nimport { getRelayAdaptContractForNetwork } from '../dop/core/providers';\nimport {\n gasEstimateResponse,\n getGasEstimate,\n setGasDetailsForTransaction,\n} from './tx-gas-details';\nimport { assertNotBlockedAddress } from '../../utils/blocked-address';\nimport {\n randomHex,\n ShieldNoteERC20,\n DopEngine,\n hexToBytes,\n} from 'dop-engine-v5';\nimport { assertValidDopAddress } from '../dop';\nimport { reportAndSanitizeError } from '../../utils/error';\nimport { ContractTransaction } from 'ethers';\n\nconst generateShieldBaseTokenTransaction = async (\n networkName: NetworkName,\n dopAddress: string,\n shieldPrivateKey: string,\n wrappedERC20Amount: DopERC20Amount,\n): Promise<ContractTransaction> => {\n try {\n const relayAdaptContract = getRelayAdaptContractForNetwork(networkName);\n const { masterPublicKey, viewingPublicKey } =\n DopEngine.decodeAddress(dopAddress);\n const random = randomHex(16);\n\n const { amount, tokenAddress } = wrappedERC20Amount;\n\n const shield = new ShieldNoteERC20(\n masterPublicKey,\n random,\n amount,\n tokenAddress,\n );\n\n const shieldRequest = await shield.serialize(\n hexToBytes(shieldPrivateKey),\n viewingPublicKey,\n );\n\n const transaction = await relayAdaptContract.populateShieldBaseToken(\n shieldRequest,\n );\n\n return transaction;\n } catch (err) {\n const sanitizedError = reportAndSanitizeError(\n generateShieldBaseTokenTransaction.name,\n err,\n );\n throw sanitizedError;\n }\n};\n\nexport const populateShieldBaseToken = async (\n networkName: NetworkName,\n dopAddress: string,\n shieldPrivateKey: string,\n wrappedERC20Amount: DopERC20Amount,\n gasDetails?: TransactionGasDetails,\n): Promise<DopPopulateTransactionResponse> => {\n try {\n assertValidDopAddress(dopAddress);\n\n const transaction = await generateShieldBaseTokenTransaction(\n networkName,\n dopAddress,\n shieldPrivateKey,\n wrappedERC20Amount,\n );\n\n if (gasDetails) {\n const sendWithPublicWallet = true;\n setGasDetailsForTransaction(\n networkName,\n transaction,\n gasDetails,\n sendWithPublicWallet,\n );\n }\n\n return {\n transaction,\n };\n } catch (err) {\n throw reportAndSanitizeError(populateShieldBaseToken.name, err);\n }\n};\n\nexport const gasEstimateForShieldBaseToken = async (\n networkName: NetworkName,\n dopAddress: string,\n shieldPrivateKey: string,\n wrappedERC20Amount: DopERC20Amount,\n fromWalletAddress: string,\n): Promise<DopTransactionGasEstimateResponse> => {\n try {\n assertValidDopAddress(dopAddress);\n assertNotBlockedAddress(fromWalletAddress);\n\n const transaction = await generateShieldBaseTokenTransaction(\n networkName,\n dopAddress,\n shieldPrivateKey,\n wrappedERC20Amount,\n );\n\n const sendWithPublicWallet = true;\n const isGasEstimateWithDummyProof = false;\n return gasEstimateResponse(\n await getGasEstimate(\n networkName,\n transaction,\n fromWalletAddress,\n sendWithPublicWallet,\n false, // isCrossContractCall\n ),\n undefined, // relayerFeeCommitment\n isGasEstimateWithDummyProof,\n );\n } catch (err) {\n throw reportAndSanitizeError(gasEstimateForShieldBaseToken.name, err);\n }\n};\n"]}
1
+ {"version":3,"file":"tx-shield-base-token.js","sourceRoot":"","sources":["../../../src/services/transactions/tx-shield-base-token.ts"],"names":[],"mappings":";;;AAOA,qDAAwE;AACxE,qDAI0B;AAC1B,iEAAsE;AACtE,iDAKuB;AACvB,gCAA+C;AAC/C,6CAA2D;AAG3D,MAAM,kCAAkC,GAAG,KAAK,EAC9C,WAAwB,EACxB,UAAkB,EAClB,gBAAwB,EACxB,kBAAkC,EAClC,iBAAyB,EACK,EAAE;IAChC,IAAI;QACF,MAAM,kBAAkB,G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,CACrB,CAAC;SACH;QAED,OAAO;YACL,WAAW;SACZ,CAAC;KACH;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAA,8BAAsB,EAAC,+BAAuB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KACjE;AACH,CAAC,CAAC;AAnCW,QAAA,uBAAuB,2BAmClC;AAEK,MAAM,6BAA6B,GAAG,KAAK,EAChD,WAAwB,EACxB,UAAkB,EAClB,gBAAwB,EACxB,kBAAkC,EAClC,iBAAyB,EACmB,EAAE;IAC9C,IAAI;QACF,IAAA,2BAAqB,EAAC,UAAU,CAAC,CAAC;QAClC,IAAA,yCAAuB,EAAC,iBAAiB,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAA;QAExD,MAAM,WAAW,GAAG,MAAM,kCAAkC,CAC1D,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,CAClB,CAAC;QAEF,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAA;QAGzD,MAAM,oBAAoB,GAAG,IAAI,CAAC;QAClC,MAAM,2BAA2B,GAAG,KAAK,CAAC;QAC1C,OAAO,IAAA,oCAAmB,EACxB,MAAM,IAAA,+BAAc,EAClB,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,KAAK,CACN,EACD,SAAS,EAAE,uBAAuB;QAClC,2BAA2B,CAC5B,CAAC;KACH;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAA,8BAAsB,EAAC,qCAA6B,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KACvE;AACH,CAAC,CAAC;AAvCW,QAAA,6BAA6B,iCAuCxC","sourcesContent":["import {\n DopPopulateTransactionResponse,\n DopTransactionGasEstimateResponse,\n DopERC20Amount,\n NetworkName,\n TransactionGasDetails,\n} from 'dop-sharedmodel-v5';\nimport { getRelayAdaptContractForNetwork } from '../dop/core/providers';\nimport {\n gasEstimateResponse,\n getGasEstimate,\n setGasDetailsForTransaction,\n} from './tx-gas-details';\nimport { assertNotBlockedAddress } from '../../utils/blocked-address';\nimport {\n randomHex,\n ShieldNoteERC20,\n DopEngine,\n hexToBytes,\n} from 'dop-engine-v5';\nimport { assertValidDopAddress } from '../dop';\nimport { reportAndSanitizeError } from '../../utils/error';\nimport { ContractTransaction } from 'ethers';\n\nconst generateShieldBaseTokenTransaction = async (\n networkName: NetworkName,\n dopAddress: string,\n shieldPrivateKey: string,\n wrappedERC20Amount: DopERC20Amount,\n fromWalletAddress: string\n): Promise<ContractTransaction> => {\n try {\n const relayAdaptContract = getRelayAdaptContractForNetwork(networkName);\n const { masterPublicKey, viewingPublicKey } =\n DopEngine.decodeAddress(dopAddress);\n const random = randomHex(16);\n\n const { amount, tokenAddress } = wrappedERC20Amount;\n\n const shield = new ShieldNoteERC20(\n masterPublicKey,\n random,\n amount,\n tokenAddress,\n );\n\n const shieldRequest = await shield.serialize(\n hexToBytes(shieldPrivateKey),\n viewingPublicKey,\n );\n console.log(\"before populateShieldBaseToken\")\n\n\n const transaction = await relayAdaptContract.populateShieldBaseToken(\n shieldRequest,\n fromWalletAddress\n );\n\n return transaction;\n } catch (err) {\n const sanitizedError = reportAndSanitizeError(\n generateShieldBaseTokenTransaction.name,\n err,\n );\n throw sanitizedError;\n }\n};\n\nexport const populateShieldBaseToken = async (\n networkName: NetworkName,\n dopAddress: string,\n shieldPrivateKey: string,\n wrappedERC20Amount: DopERC20Amount,\n fromWalletAddress: string,\n gasDetails?: TransactionGasDetails,\n): Promise<DopPopulateTransactionResponse> => {\n try {\n assertValidDopAddress(dopAddress);\n\n const transaction = await generateShieldBaseTokenTransaction(\n networkName,\n dopAddress,\n shieldPrivateKey,\n wrappedERC20Amount,\n fromWalletAddress,\n );\n\n if (gasDetails) {\n const sendWithPublicWallet = true;\n setGasDetailsForTransaction(\n networkName,\n transaction,\n gasDetails,\n sendWithPublicWallet,\n );\n }\n\n return {\n transaction,\n };\n } catch (err) {\n throw reportAndSanitizeError(populateShieldBaseToken.name, err);\n }\n};\n\nexport const gasEstimateForShieldBaseToken = async (\n networkName: NetworkName,\n dopAddress: string,\n shieldPrivateKey: string,\n wrappedERC20Amount: DopERC20Amount,\n fromWalletAddress: string,\n): Promise<DopTransactionGasEstimateResponse> => {\n try {\n assertValidDopAddress(dopAddress);\n assertNotBlockedAddress(fromWalletAddress);\n console.log(\"before generateShieldBaseTokenTransaction\")\n\n const transaction = await generateShieldBaseTokenTransaction(\n networkName,\n dopAddress,\n shieldPrivateKey,\n wrappedERC20Amount,\n fromWalletAddress,\n );\n\n console.log(\"before generateShieldBaseTokenTransaction2\")\n\n\n const sendWithPublicWallet = true;\n const isGasEstimateWithDummyProof = false;\n return gasEstimateResponse(\n await getGasEstimate(\n networkName,\n transaction,\n fromWalletAddress,\n sendWithPublicWallet,\n false, // isCrossContractCall\n ),\n undefined, // relayerFeeCommitment\n isGasEstimateWithDummyProof,\n );\n } catch (err) {\n throw reportAndSanitizeError(gasEstimateForShieldBaseToken.name, err);\n }\n};\n"]}
@@ -38,7 +38,9 @@ const generateShieldTransaction = async (networkName, shieldPrivateKey, erc20Amo
38
38
  ...erc20AmountRecipients.map(erc20AmountRecipient => generateERC20ShieldRequests(erc20AmountRecipient, random, shieldPrivateKey)),
39
39
  ...nftAmountRecipients.map(nftAmountRecipient => generateNFTShieldRequests(nftAmountRecipient, random, shieldPrivateKey)),
40
40
  ]);
41
+ console.log("shieldInputs:::", shieldInputs);
41
42
  const transaction = await dopSmartWalletContract.generateShield(shieldInputs);
43
+ console.log("transaction:::", transaction);
42
44
  return transaction;
43
45
  }
44
46
  catch (err) {
@@ -50,6 +52,7 @@ exports.generateShieldTransaction = generateShieldTransaction;
50
52
  const populateShield = async (networkName, shieldPrivateKey, erc20AmountRecipients, nftAmountRecipients, gasDetails) => {
51
53
  try {
52
54
  const transaction = await (0, exports.generateShieldTransaction)(networkName, shieldPrivateKey, erc20AmountRecipients, nftAmountRecipients);
55
+ console.log("transaction:::0", transaction);
53
56
  if (gasDetails) {
54
57
  const sendWithPublicWallet = true;
55
58
  (0, tx_gas_details_1.setGasDetailsForTransaction)(networkName, transaction, gasDetails, sendWithPublicWallet);
@@ -67,6 +70,7 @@ const gasEstimateForShield = async (networkName, shieldPrivateKey, erc20AmountRe
67
70
  try {
68
71
  (0, blocked_address_1.assertNotBlockedAddress)(fromWalletAddress);
69
72
  const transaction = await (0, exports.generateShieldTransaction)(networkName, shieldPrivateKey, erc20AmountRecipients, nftAmountRecipients);
73
+ console.log("transaction:::1", transaction);
70
74
  const sendWithPublicWallet = true;
71
75
  const isGasEstimateWithDummyProof = false;
72
76
  return (0, tx_gas_details_1.gasEstimateResponse)(await (0, tx_gas_details_1.getGasEstimate)(networkName, transaction, fromWalletAddress, sendWithPublicWallet, false), undefined, // relayerFeeCommitment
@@ -1 +1 @@
1
- {"version":3,"file":"tx-shield.js","sourceRoot":"","sources":["../../../src/services/transactions/tx-shield.ts"],"names":[],"mappings":";;;AAAA,2DAQ4B;AAC5B,iDASuB;AACvB,qDAI0B;AAC1B,iEAAsE;AACtE,gCAGgB;AAChB,uEAA+E;AAC/E,6CAA2D;AAGpD,MAAM,mCAAmC,GAAG,GAAG,EAAE;IACtD,OAAO,0BAAU,CAAC,mCAAmC,EAAE,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mCAAmC,uCAE9C;AAEF,MAAM,2BAA2B,GAAG,KAAK,EACvC,oBAA6C,EAC7C,MAAc,EACd,gBAAwB,EACM,EAAE;IAChC,MAAM,UAAU,GAAG,oBAAoB,CAAC,gBAAgB,CAAC;IAEzD,IAAA,2BAAqB,EAAC,UAAU,CAAC,CAAC;IAElC,MAAM,EAAE,eAAe,EAAE,gBAAgB,EAAE,GACzC,yBAAS,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAEtC,MAAM,MAAM,GAAG,IAAI,+BAAe,CAChC,eAAe,EACf,MAAM,EACN,oBAAoB,CAAC,MAAM,EAC3B,oBAAoB,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MAAM,IAAA,iCAAyB,EACjD,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,CACpB,CAAC;QAGF,MAAM,oBAAoB,GAAG,IAAI,CAAC;QAClC,MAAM,2BAA2B,GAAG,KAAK,CAAC;QAC1C,OAAO,IAAA,oCAAmB,EACxB,MAAM,IAAA,+BAAc,EAClB,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,KAAK,CACN,EACD,SAAS,EAAE,uBAAuB;QAClC,2BAA2B,CAC5B,CAAC;KACH;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAA,8BAAsB,EAAC,4BAAoB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KAC9D;AACH,CAAC,CAAC;AAlCW,QAAA,oBAAoB,wBAkC/B","sourcesContent":["import {\n DopPopulateTransactionResponse,\n DopTransactionGasEstimateResponse,\n NetworkName,\n DopERC20AmountRecipient,\n DopNFTAmountRecipient,\n NFTTokenType,\n TransactionGasDetails,\n} from 'dop-sharedmodel-v5';\nimport {\n ShieldNote,\n DopEngine,\n ShieldRequestStruct,\n randomHex,\n hexToBytes,\n ShieldNoteERC20,\n ShieldNoteNFT,\n ERC721_NOTE_VALUE,\n} from 'dop-engine-v5';\nimport {\n gasEstimateResponse,\n getGasEstimate,\n setGasDetailsForTransaction,\n} from './tx-gas-details';\nimport { assertNotBlockedAddress } from '../../utils/blocked-address';\nimport {\n assertValidDopAddress,\n getDopSmartWalletContractForNetwork,\n} from '../dop';\nimport { createNFTTokenDataFromDopNFTAmount } from './tx-cross-contract-calls';\nimport { reportAndSanitizeError } from '../../utils/error';\nimport { ContractTransaction } from 'ethers';\n\nexport const getShieldPrivateKeySignatureMessage = () => {\n return ShieldNote.getShieldPrivateKeySignatureMessage();\n};\n\nconst generateERC20ShieldRequests = async (\n erc20AmountRecipient: DopERC20AmountRecipient,\n random: string,\n shieldPrivateKey: string,\n): Promise<ShieldRequestStruct> => {\n const dopAddress = erc20AmountRecipient.recipientAddress;\n\n assertValidDopAddress(dopAddress);\n\n const { masterPublicKey, viewingPublicKey } =\n DopEngine.decodeAddress(dopAddress);\n\n const shield = new ShieldNoteERC20(\n masterPublicKey,\n random,\n erc20AmountRecipient.amount,\n erc20AmountRecipient.tokenAddress,\n );\n return shield.serialize(hexToBytes(shieldPrivateKey), viewingPublicKey);\n};\n\nconst generateNFTShieldRequests = async (\n nftAmountRecipient: DopNFTAmountRecipient,\n random: string,\n shieldPrivateKey: string,\n): Promise<ShieldRequestStruct> => {\n const dopAddress = nftAmountRecipient.recipientAddress;\n\n assertValidDopAddress(dopAddress);\n\n const { masterPublicKey, viewingPublicKey } =\n DopEngine.decodeAddress(dopAddress);\n\n const value =\n nftAmountRecipient.nftTokenType === NFTTokenType.ERC721\n ? ERC721_NOTE_VALUE\n : nftAmountRecipient.amount;\n\n\n const nftTokenData =\n createNFTTokenDataFromDopNFTAmount(nftAmountRecipient);\n\n const shield = new ShieldNoteNFT(\n masterPublicKey,\n random,\n value,\n nftTokenData,\n );\n\n return shield.serialize(hexToBytes(shieldPrivateKey), viewingPublicKey);\n};\n\nexport const generateShieldTransaction = async (\n networkName: NetworkName,\n shieldPrivateKey: string,\n erc20AmountRecipients: DopERC20AmountRecipient[],\n nftAmountRecipients: DopNFTAmountRecipient[],\n): Promise<ContractTransaction> => {\n try {\n const dopSmartWalletContract =\n getDopSmartWalletContractForNetwork(networkName);\n\n const random = randomHex(16);\n\n const shieldInputs: ShieldRequestStruct[] = await Promise.all([\n ...erc20AmountRecipients.map(erc20AmountRecipient =>\n generateERC20ShieldRequests(\n erc20AmountRecipient,\n random,\n shieldPrivateKey,\n ),\n ),\n ...nftAmountRecipients.map(nftAmountRecipient =>\n generateNFTShieldRequests(nftAmountRecipient, random, shieldPrivateKey),\n ),\n ]);\n\n const transaction = await dopSmartWalletContract.generateShield(\n shieldInputs,\n );\n\n return transaction;\n } catch (err) {\n const sanitizedError = reportAndSanitizeError(\n generateShieldTransaction.name,\n err,\n );\n throw sanitizedError;\n }\n};\n\nexport const populateShield = async (\n networkName: NetworkName,\n shieldPrivateKey: string,\n erc20AmountRecipients: DopERC20AmountRecipient[],\n nftAmountRecipients: DopNFTAmountRecipient[],\n gasDetails?: TransactionGasDetails,\n): Promise<DopPopulateTransactionResponse> => {\n try {\n const transaction = await generateShieldTransaction(\n networkName,\n shieldPrivateKey,\n erc20AmountRecipients,\n nftAmountRecipients,\n );\n\n if (gasDetails) {\n const sendWithPublicWallet = true;\n setGasDetailsForTransaction(\n networkName,\n transaction,\n gasDetails,\n sendWithPublicWallet,\n );\n }\n\n return {\n transaction,\n };\n } catch (err) {\n throw reportAndSanitizeError(populateShield.name, err);\n }\n};\n\nexport const gasEstimateForShield = async (\n networkName: NetworkName,\n shieldPrivateKey: string,\n erc20AmountRecipients: DopERC20AmountRecipient[],\n nftAmountRecipients: DopNFTAmountRecipient[],\n fromWalletAddress: string,\n): Promise<DopTransactionGasEstimateResponse> => {\n try {\n assertNotBlockedAddress(fromWalletAddress);\n\n const transaction = await generateShieldTransaction(\n networkName,\n shieldPrivateKey,\n erc20AmountRecipients,\n nftAmountRecipients,\n );\n\n\n const sendWithPublicWallet = true;\n const isGasEstimateWithDummyProof = false;\n return gasEstimateResponse(\n await getGasEstimate(\n networkName,\n transaction,\n fromWalletAddress,\n sendWithPublicWallet,\n false, // isCrossContractCall\n ),\n undefined, // relayerFeeCommitment\n isGasEstimateWithDummyProof,\n );\n } catch (err) {\n throw reportAndSanitizeError(gasEstimateForShield.name, err);\n }\n};\n"]}
1
+ {"version":3,"file":"tx-shield.js","sourceRoot":"","sources":["../../../src/services/transactions/tx-shield.ts"],"names":[],"mappings":";;;AAAA,2DAQ4B;AAC5B,iDASuB;AACvB,qDAI0B;AAC1B,iEAAsE;AACtE,gCAGgB;AAChB,uEAA+E;AAC/E,6CAA2D;AAGpD,MAAM,mCAAmC,GAAG,GAAG,EAAE;IACtD,OAAO,0BAAU,CAAC,mCAAmC,EAAE,CAAC;AAC1D,C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n DopERC20AmountRecipient,\n DopNFTAmountRecipient,\n NFTTokenType,\n TransactionGasDetails,\n} from 'dop-sharedmodel-v5';\nimport {\n ShieldNote,\n DopEngine,\n ShieldRequestStruct,\n randomHex,\n hexToBytes,\n ShieldNoteERC20,\n ShieldNoteNFT,\n ERC721_NOTE_VALUE,\n} from 'dop-engine-v5';\nimport {\n gasEstimateResponse,\n getGasEstimate,\n setGasDetailsForTransaction,\n} from './tx-gas-details';\nimport { assertNotBlockedAddress } from '../../utils/blocked-address';\nimport {\n assertValidDopAddress,\n getDopSmartWalletContractForNetwork,\n} from '../dop';\nimport { createNFTTokenDataFromDopNFTAmount } from './tx-cross-contract-calls';\nimport { reportAndSanitizeError } from '../../utils/error';\nimport { ContractTransaction } from 'ethers';\n\nexport const getShieldPrivateKeySignatureMessage = () => {\n return ShieldNote.getShieldPrivateKeySignatureMessage();\n};\n\nconst generateERC20ShieldRequests = async (\n erc20AmountRecipient: DopERC20AmountRecipient,\n random: string,\n shieldPrivateKey: string,\n): Promise<ShieldRequestStruct> => {\n const dopAddress = erc20AmountRecipient.recipientAddress;\n\n assertValidDopAddress(dopAddress);\n\n const { masterPublicKey, viewingPublicKey } =\n DopEngine.decodeAddress(dopAddress);\n\n const shield = new ShieldNoteERC20(\n masterPublicKey,\n random,\n erc20AmountRecipient.amount,\n erc20AmountRecipient.tokenAddress,\n );\n return shield.serialize(hexToBytes(shieldPrivateKey), viewingPublicKey);\n};\n\nconst generateNFTShieldRequests = async (\n nftAmountRecipient: DopNFTAmountRecipient,\n random: string,\n shieldPrivateKey: string,\n): Promise<ShieldRequestStruct> => {\n const dopAddress = nftAmountRecipient.recipientAddress;\n\n assertValidDopAddress(dopAddress);\n\n const { masterPublicKey, viewingPublicKey } =\n DopEngine.decodeAddress(dopAddress);\n\n const value =\n nftAmountRecipient.nftTokenType === NFTTokenType.ERC721\n ? ERC721_NOTE_VALUE\n : nftAmountRecipient.amount;\n\n\n const nftTokenData =\n createNFTTokenDataFromDopNFTAmount(nftAmountRecipient);\n\n const shield = new ShieldNoteNFT(\n masterPublicKey,\n random,\n value,\n nftTokenData,\n );\n\n return shield.serialize(hexToBytes(shieldPrivateKey), viewingPublicKey);\n};\n\nexport const generateShieldTransaction = async (\n networkName: NetworkName,\n shieldPrivateKey: string,\n erc20AmountRecipients: DopERC20AmountRecipient[],\n nftAmountRecipients: DopNFTAmountRecipient[],\n): Promise<ContractTransaction> => {\n try {\n const dopSmartWalletContract =\n getDopSmartWalletContractForNetwork(networkName);\n\n const random = randomHex(16);\n\n const shieldInputs: ShieldRequestStruct[] = await Promise.all([\n ...erc20AmountRecipients.map(erc20AmountRecipient =>\n generateERC20ShieldRequests(\n erc20AmountRecipient,\n random,\n shieldPrivateKey,\n ),\n ),\n ...nftAmountRecipients.map(nftAmountRecipient =>\n generateNFTShieldRequests(nftAmountRecipient, random, shieldPrivateKey),\n ),\n ]);\n console.log(\"shieldInputs:::\", shieldInputs);\n\n const transaction = await dopSmartWalletContract.generateShield(\n shieldInputs,\n );\n console.log(\"transaction:::\", transaction);\n\n\n return transaction;\n } catch (err) {\n const sanitizedError = reportAndSanitizeError(\n generateShieldTransaction.name,\n err,\n );\n throw sanitizedError;\n }\n};\n\nexport const populateShield = async (\n networkName: NetworkName,\n shieldPrivateKey: string,\n erc20AmountRecipients: DopERC20AmountRecipient[],\n nftAmountRecipients: DopNFTAmountRecipient[],\n gasDetails?: TransactionGasDetails,\n): Promise<DopPopulateTransactionResponse> => {\n try {\n const transaction = await generateShieldTransaction(\n networkName,\n shieldPrivateKey,\n erc20AmountRecipients,\n nftAmountRecipients,\n );\n console.log(\"transaction:::0\", transaction);\n\n\n if (gasDetails) {\n const sendWithPublicWallet = true;\n setGasDetailsForTransaction(\n networkName,\n transaction,\n gasDetails,\n sendWithPublicWallet,\n );\n }\n\n return {\n transaction,\n };\n } catch (err) {\n throw reportAndSanitizeError(populateShield.name, err);\n }\n};\n\nexport const gasEstimateForShield = async (\n networkName: NetworkName,\n shieldPrivateKey: string,\n erc20AmountRecipients: DopERC20AmountRecipient[],\n nftAmountRecipients: DopNFTAmountRecipient[],\n fromWalletAddress: string,\n): Promise<DopTransactionGasEstimateResponse> => {\n try {\n assertNotBlockedAddress(fromWalletAddress);\n\n const transaction = await generateShieldTransaction(\n networkName,\n shieldPrivateKey,\n erc20AmountRecipients,\n nftAmountRecipients,\n );\n console.log(\"transaction:::1\", transaction);\n\n\n const sendWithPublicWallet = true;\n const isGasEstimateWithDummyProof = false;\n return gasEstimateResponse(\n await getGasEstimate(\n networkName,\n transaction,\n fromWalletAddress,\n sendWithPublicWallet,\n false, // isCrossContractCall\n ),\n undefined, // relayerFeeCommitment\n isGasEstimateWithDummyProof,\n );\n } catch (err) {\n throw reportAndSanitizeError(gasEstimateForShield.name, err);\n }\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dop-wallet-v6",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "DOP Wallet SDK, compatible with mobile, browser and nodejs environments.",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
@@ -38,22 +38,23 @@
38
38
  "@graphql-mesh/types": "^0.91.14",
39
39
  "@graphql-mesh/utils": "^0.43.22",
40
40
  "@noble/ed25519": "^1.7.1",
41
- "dop-engine-v5": "1.1.6",
42
- "dop-sharedmodel-v5": "1.1.6",
43
41
  "@whatwg-node/fetch": "^0.8.4",
44
42
  "assert": "2.0.0",
43
+ "axios": "0.27.2",
44
+ "brotli": "^1.3.3",
45
45
  "buffer": "^6.0.3",
46
46
  "crypto-browserify": "3.12.0",
47
- "ethers": "github:web3-devv/ethers.js#v6.7.6",
47
+ "dop-engine-v5": "1.1.8",
48
+ "dop-sharedmodel-v5": "1.1.8",
48
49
  "ethereum-cryptography": "^2.0.0",
50
+ "ethers": "github:web3-devv/ethers.js#v6.7.6",
49
51
  "events": "3.3.0",
50
- "axios": "0.27.2",
51
- "brotli": "^1.3.3",
52
52
  "graphql": "^16.6.0",
53
53
  "stream-browserify": "3.0.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@graphprotocol/client-cli": "^2.2.20",
57
+ "@types/abstract-leveldown": "^7.2.5",
57
58
  "@types/chai": "^4.3.4",
58
59
  "@types/chai-as-promised": "^7.1.5",
59
60
  "@types/leveldown": "^4.0.3",