@skalenetwork/privacy-sdk 0.1.0-develop.0 → 0.1.0-develop.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -8
- package/dist/actions/index.cjs +165 -118
- package/dist/actions/index.cjs.map +1 -1
- package/dist/actions/index.d.cts +16 -18
- package/dist/actions/index.d.ts +16 -18
- package/dist/actions/index.js +5 -9
- package/dist/{chunk-YEII26VS.js → chunk-PMT6KSGL.js} +157 -76
- package/dist/chunk-PMT6KSGL.js.map +1 -0
- package/dist/index.cjs +179 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -11
- package/dist/index.d.ts +88 -11
- package/dist/index.js +17 -18
- package/dist/index.js.map +1 -1
- package/dist/types-CPLzL9IK.d.ts +13 -0
- package/dist/types-T84pCSPm.d.cts +13 -0
- package/package.json +6 -9
- package/dist/chunk-YEII26VS.js.map +0 -1
- package/dist/types-CBDYydn0.d.cts +0 -60
- package/dist/types-Gn0F4pQf.d.ts +0 -60
package/dist/index.cjs
CHANGED
|
@@ -27,16 +27,21 @@ __export(index_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/ConfidentialToken.ts
|
|
30
|
-
var
|
|
30
|
+
var import_viem6 = require("viem");
|
|
31
31
|
var import_bite = require("@skalenetwork/bite");
|
|
32
32
|
|
|
33
33
|
// src/actions/transfers.ts
|
|
34
|
-
var
|
|
34
|
+
var import_viem = require("viem");
|
|
35
35
|
|
|
36
36
|
// src/abi/confidentialWrapper.ts
|
|
37
37
|
var confidentialWrapperAbi = [
|
|
38
38
|
{
|
|
39
39
|
inputs: [
|
|
40
|
+
{
|
|
41
|
+
internalType: "bool",
|
|
42
|
+
name: "proxyMode",
|
|
43
|
+
type: "bool"
|
|
44
|
+
},
|
|
40
45
|
{
|
|
41
46
|
internalType: "contract IERC20Metadata",
|
|
42
47
|
name: "underlyingToken",
|
|
@@ -602,6 +607,11 @@ var confidentialWrapperAbi = [
|
|
|
602
607
|
name: "InvalidDataOffset",
|
|
603
608
|
type: "error"
|
|
604
609
|
},
|
|
610
|
+
{
|
|
611
|
+
inputs: [],
|
|
612
|
+
name: "InvalidInitialization",
|
|
613
|
+
type: "error"
|
|
614
|
+
},
|
|
605
615
|
{
|
|
606
616
|
inputs: [],
|
|
607
617
|
name: "InvalidPublicKey",
|
|
@@ -630,7 +640,7 @@ var confidentialWrapperAbi = [
|
|
|
630
640
|
},
|
|
631
641
|
{
|
|
632
642
|
inputs: [],
|
|
633
|
-
name: "
|
|
643
|
+
name: "InvalidSaltForTransactionValue",
|
|
634
644
|
type: "error"
|
|
635
645
|
},
|
|
636
646
|
{
|
|
@@ -676,6 +686,11 @@ var confidentialWrapperAbi = [
|
|
|
676
686
|
name: "NoViewerRegisteredForHolder",
|
|
677
687
|
type: "error"
|
|
678
688
|
},
|
|
689
|
+
{
|
|
690
|
+
inputs: [],
|
|
691
|
+
name: "NotInitializing",
|
|
692
|
+
type: "error"
|
|
693
|
+
},
|
|
679
694
|
{
|
|
680
695
|
inputs: [
|
|
681
696
|
{
|
|
@@ -714,17 +729,6 @@ var confidentialWrapperAbi = [
|
|
|
714
729
|
name: "SafeERC20FailedOperation",
|
|
715
730
|
type: "error"
|
|
716
731
|
},
|
|
717
|
-
{
|
|
718
|
-
inputs: [
|
|
719
|
-
{
|
|
720
|
-
internalType: "string",
|
|
721
|
-
name: "str",
|
|
722
|
-
type: "string"
|
|
723
|
-
}
|
|
724
|
-
],
|
|
725
|
-
name: "StringTooLong",
|
|
726
|
-
type: "error"
|
|
727
|
-
},
|
|
728
732
|
{
|
|
729
733
|
inputs: [
|
|
730
734
|
{
|
|
@@ -784,6 +788,11 @@ var confidentialWrapperAbi = [
|
|
|
784
788
|
name: "ValueWasNotEncryptedCorrectly",
|
|
785
789
|
type: "error"
|
|
786
790
|
},
|
|
791
|
+
{
|
|
792
|
+
inputs: [],
|
|
793
|
+
name: "WrongInitializer",
|
|
794
|
+
type: "error"
|
|
795
|
+
},
|
|
787
796
|
{
|
|
788
797
|
inputs: [],
|
|
789
798
|
name: "WrongPlaintextFormat",
|
|
@@ -1140,6 +1149,19 @@ var confidentialWrapperAbi = [
|
|
|
1140
1149
|
name: "HistoricViewTransferIdRevoked",
|
|
1141
1150
|
type: "event"
|
|
1142
1151
|
},
|
|
1152
|
+
{
|
|
1153
|
+
anonymous: false,
|
|
1154
|
+
inputs: [
|
|
1155
|
+
{
|
|
1156
|
+
indexed: false,
|
|
1157
|
+
internalType: "uint64",
|
|
1158
|
+
name: "version",
|
|
1159
|
+
type: "uint64"
|
|
1160
|
+
}
|
|
1161
|
+
],
|
|
1162
|
+
name: "Initialized",
|
|
1163
|
+
type: "event"
|
|
1164
|
+
},
|
|
1143
1165
|
{
|
|
1144
1166
|
anonymous: false,
|
|
1145
1167
|
inputs: [
|
|
@@ -1772,6 +1794,30 @@ var confidentialWrapperAbi = [
|
|
|
1772
1794
|
stateMutability: "view",
|
|
1773
1795
|
type: "function"
|
|
1774
1796
|
},
|
|
1797
|
+
{
|
|
1798
|
+
inputs: [
|
|
1799
|
+
{
|
|
1800
|
+
internalType: "address",
|
|
1801
|
+
name: "holder",
|
|
1802
|
+
type: "address"
|
|
1803
|
+
},
|
|
1804
|
+
{
|
|
1805
|
+
internalType: "uint256",
|
|
1806
|
+
name: "value",
|
|
1807
|
+
type: "uint256"
|
|
1808
|
+
}
|
|
1809
|
+
],
|
|
1810
|
+
name: "encryptValue",
|
|
1811
|
+
outputs: [
|
|
1812
|
+
{
|
|
1813
|
+
internalType: "bytes",
|
|
1814
|
+
name: "encryptedValue",
|
|
1815
|
+
type: "bytes"
|
|
1816
|
+
}
|
|
1817
|
+
],
|
|
1818
|
+
stateMutability: "view",
|
|
1819
|
+
type: "function"
|
|
1820
|
+
},
|
|
1775
1821
|
{
|
|
1776
1822
|
inputs: [
|
|
1777
1823
|
{
|
|
@@ -1841,7 +1887,7 @@ var confidentialWrapperAbi = [
|
|
|
1841
1887
|
],
|
|
1842
1888
|
name: "encryptedReceiveWithAuthorization",
|
|
1843
1889
|
outputs: [],
|
|
1844
|
-
stateMutability: "
|
|
1890
|
+
stateMutability: "payable",
|
|
1845
1891
|
type: "function"
|
|
1846
1892
|
},
|
|
1847
1893
|
{
|
|
@@ -1970,6 +2016,57 @@ var confidentialWrapperAbi = [
|
|
|
1970
2016
|
stateMutability: "view",
|
|
1971
2017
|
type: "function"
|
|
1972
2018
|
},
|
|
2019
|
+
{
|
|
2020
|
+
inputs: [
|
|
2021
|
+
{
|
|
2022
|
+
internalType: "string",
|
|
2023
|
+
name: "",
|
|
2024
|
+
type: "string"
|
|
2025
|
+
},
|
|
2026
|
+
{
|
|
2027
|
+
internalType: "string",
|
|
2028
|
+
name: "",
|
|
2029
|
+
type: "string"
|
|
2030
|
+
},
|
|
2031
|
+
{
|
|
2032
|
+
internalType: "string",
|
|
2033
|
+
name: "",
|
|
2034
|
+
type: "string"
|
|
2035
|
+
},
|
|
2036
|
+
{
|
|
2037
|
+
internalType: "address",
|
|
2038
|
+
name: "",
|
|
2039
|
+
type: "address"
|
|
2040
|
+
}
|
|
2041
|
+
],
|
|
2042
|
+
name: "initialize",
|
|
2043
|
+
outputs: [],
|
|
2044
|
+
stateMutability: "pure",
|
|
2045
|
+
type: "function"
|
|
2046
|
+
},
|
|
2047
|
+
{
|
|
2048
|
+
inputs: [
|
|
2049
|
+
{
|
|
2050
|
+
internalType: "contract IERC20Metadata",
|
|
2051
|
+
name: "underlyingToken",
|
|
2052
|
+
type: "address"
|
|
2053
|
+
},
|
|
2054
|
+
{
|
|
2055
|
+
internalType: "string",
|
|
2056
|
+
name: "version_",
|
|
2057
|
+
type: "string"
|
|
2058
|
+
},
|
|
2059
|
+
{
|
|
2060
|
+
internalType: "address",
|
|
2061
|
+
name: "initialAuthority",
|
|
2062
|
+
type: "address"
|
|
2063
|
+
}
|
|
2064
|
+
],
|
|
2065
|
+
name: "initialize",
|
|
2066
|
+
outputs: [],
|
|
2067
|
+
stateMutability: "nonpayable",
|
|
2068
|
+
type: "function"
|
|
2069
|
+
},
|
|
1973
2070
|
{
|
|
1974
2071
|
inputs: [],
|
|
1975
2072
|
name: "isConsumingScheduledOp",
|
|
@@ -2674,7 +2771,6 @@ var confidentialWrapperAbi = [
|
|
|
2674
2771
|
];
|
|
2675
2772
|
|
|
2676
2773
|
// src/actions/funding.ts
|
|
2677
|
-
var import_viem = require("viem");
|
|
2678
2774
|
var CTX_RESERVE_THRESHOLD = 1n;
|
|
2679
2775
|
async function getCtxBalance(config) {
|
|
2680
2776
|
return await config.publicClient.readContract({
|
|
@@ -2684,75 +2780,78 @@ async function getCtxBalance(config) {
|
|
|
2684
2780
|
args: [config.signer.address]
|
|
2685
2781
|
});
|
|
2686
2782
|
}
|
|
2687
|
-
async function
|
|
2783
|
+
async function getCtxRawCost(config) {
|
|
2688
2784
|
return await config.publicClient.readContract({
|
|
2689
2785
|
address: config.address,
|
|
2690
2786
|
abi: confidentialWrapperAbi,
|
|
2691
2787
|
functionName: "callbackFee"
|
|
2692
2788
|
});
|
|
2693
2789
|
}
|
|
2694
|
-
async function
|
|
2695
|
-
const [fee, balance] = await Promise.all([
|
|
2790
|
+
async function getCtxOperationCost(config) {
|
|
2791
|
+
const [fee, balance] = await Promise.all([getCtxRawCost(config), getCtxBalance(config)]);
|
|
2696
2792
|
const topUp = CTX_RESERVE_THRESHOLD * fee - balance;
|
|
2697
2793
|
return fee + (topUp > 0n ? topUp : 0n);
|
|
2698
2794
|
}
|
|
2699
2795
|
|
|
2700
2796
|
// src/actions/transfers.ts
|
|
2701
|
-
async function approve(config,
|
|
2702
|
-
const data = (0,
|
|
2797
|
+
async function approve(config, spender, amount) {
|
|
2798
|
+
const data = (0, import_viem.encodeFunctionData)({
|
|
2703
2799
|
abi: confidentialWrapperAbi,
|
|
2704
2800
|
functionName: "approve",
|
|
2705
|
-
args: [
|
|
2801
|
+
args: [spender, amount]
|
|
2706
2802
|
});
|
|
2707
2803
|
return config.signer.sendTransaction({ to: config.address, data });
|
|
2708
2804
|
}
|
|
2709
|
-
async function transfer(config,
|
|
2710
|
-
const value = await
|
|
2711
|
-
const valueHex = (0,
|
|
2805
|
+
async function transfer(config, to, amount) {
|
|
2806
|
+
const value = await getCtxOperationCost(config);
|
|
2807
|
+
const valueHex = (0, import_viem.encodeAbiParameters)(
|
|
2808
|
+
[{ type: "address" }, { type: "uint256" }],
|
|
2809
|
+
[config.signer.address, amount]
|
|
2810
|
+
);
|
|
2712
2811
|
const encryptedValue = await config.bite.encryptMessageForCTX(valueHex, config.address);
|
|
2713
|
-
const data = (0,
|
|
2812
|
+
const data = (0, import_viem.encodeFunctionData)({
|
|
2714
2813
|
abi: confidentialWrapperAbi,
|
|
2715
2814
|
functionName: "encryptedTransfer",
|
|
2716
|
-
args: [
|
|
2815
|
+
args: [to, encryptedValue]
|
|
2717
2816
|
});
|
|
2718
2817
|
return config.signer.sendTransaction({ to: config.address, data, value });
|
|
2719
2818
|
}
|
|
2720
|
-
async function wrap(config,
|
|
2721
|
-
const value = await
|
|
2722
|
-
const data = (0,
|
|
2819
|
+
async function wrap(config, receiver, amount) {
|
|
2820
|
+
const value = await getCtxOperationCost(config);
|
|
2821
|
+
const data = (0, import_viem.encodeFunctionData)({
|
|
2723
2822
|
abi: confidentialWrapperAbi,
|
|
2724
2823
|
functionName: "depositForWithGasToken",
|
|
2725
|
-
args: [
|
|
2824
|
+
args: [receiver, amount]
|
|
2726
2825
|
});
|
|
2727
2826
|
return config.signer.sendTransaction({ to: config.address, data, value });
|
|
2728
2827
|
}
|
|
2729
|
-
async function unwrap(config,
|
|
2730
|
-
const value = await
|
|
2731
|
-
const data = (0,
|
|
2828
|
+
async function unwrap(config, receiver, amount) {
|
|
2829
|
+
const value = await getCtxOperationCost(config);
|
|
2830
|
+
const data = (0, import_viem.encodeFunctionData)({
|
|
2732
2831
|
abi: confidentialWrapperAbi,
|
|
2733
2832
|
functionName: "withdrawToWithGasToken",
|
|
2734
|
-
args: [
|
|
2833
|
+
args: [receiver, amount]
|
|
2735
2834
|
});
|
|
2736
2835
|
return config.signer.sendTransaction({ to: config.address, data, value });
|
|
2737
2836
|
}
|
|
2738
2837
|
|
|
2739
2838
|
// src/actions/decrypt.ts
|
|
2740
|
-
var
|
|
2839
|
+
var import_viem3 = require("viem");
|
|
2741
2840
|
|
|
2742
2841
|
// src/utils/crypto.ts
|
|
2743
2842
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
|
2744
2843
|
var import_sha256 = require("@noble/hashes/sha256");
|
|
2745
2844
|
var import_aes = require("@noble/ciphers/aes");
|
|
2746
|
-
var
|
|
2845
|
+
var import_viem2 = require("viem");
|
|
2747
2846
|
function bytesToBigInt(bytes) {
|
|
2748
2847
|
if (bytes.length === 0) {
|
|
2749
2848
|
return 0n;
|
|
2750
2849
|
}
|
|
2751
|
-
const hexValue = (0,
|
|
2850
|
+
const hexValue = (0, import_viem2.bytesToHex)(bytes);
|
|
2752
2851
|
return BigInt(hexValue === "0x" ? "0x0" : hexValue);
|
|
2753
2852
|
}
|
|
2754
2853
|
function decryptEciesPayload(encryptedHex, privateKey) {
|
|
2755
|
-
const payload = (0,
|
|
2854
|
+
const payload = (0, import_viem2.hexToBytes)(encryptedHex);
|
|
2756
2855
|
if (payload.length < 65) {
|
|
2757
2856
|
throw new Error("Encrypted payload is too short.");
|
|
2758
2857
|
}
|
|
@@ -2766,7 +2865,7 @@ function decryptEciesPayload(encryptedHex, privateKey) {
|
|
|
2766
2865
|
throw new Error("Invalid AES-CBC ciphertext length.");
|
|
2767
2866
|
}
|
|
2768
2867
|
const sharedSecret = import_secp256k1.secp256k1.getSharedSecret(
|
|
2769
|
-
(0,
|
|
2868
|
+
(0, import_viem2.hexToBytes)(privateKey),
|
|
2770
2869
|
ephemeralCompressedPublicKey,
|
|
2771
2870
|
true
|
|
2772
2871
|
);
|
|
@@ -2776,7 +2875,7 @@ function decryptEciesPayload(encryptedHex, privateKey) {
|
|
|
2776
2875
|
}
|
|
2777
2876
|
function tryDecodeTransferData(encoded) {
|
|
2778
2877
|
try {
|
|
2779
|
-
const [from, to, value, timestamp, transferId] = (0,
|
|
2878
|
+
const [from, to, value, timestamp, transferId] = (0, import_viem2.decodeAbiParameters)(
|
|
2780
2879
|
[
|
|
2781
2880
|
{ type: "address" },
|
|
2782
2881
|
{ type: "address" },
|
|
@@ -2800,14 +2899,14 @@ async function decryptBalance(encryptedHex, privateKey) {
|
|
|
2800
2899
|
}
|
|
2801
2900
|
async function decryptTransferData(encryptedHex, privateKey) {
|
|
2802
2901
|
const plaintext = decryptEciesPayload(encryptedHex, privateKey);
|
|
2803
|
-
const direct = tryDecodeTransferData((0,
|
|
2902
|
+
const direct = tryDecodeTransferData((0, import_viem2.bytesToHex)(plaintext));
|
|
2804
2903
|
if (direct) {
|
|
2805
2904
|
return direct;
|
|
2806
2905
|
}
|
|
2807
2906
|
const structSizeBytes = 32 * 5;
|
|
2808
2907
|
if (plaintext.length >= structSizeBytes) {
|
|
2809
2908
|
const trailing = plaintext.slice(-structSizeBytes);
|
|
2810
|
-
const trailingDecoded = tryDecodeTransferData((0,
|
|
2909
|
+
const trailingDecoded = tryDecodeTransferData((0, import_viem2.bytesToHex)(trailing));
|
|
2811
2910
|
if (trailingDecoded) {
|
|
2812
2911
|
return trailingDecoded;
|
|
2813
2912
|
}
|
|
@@ -2816,25 +2915,22 @@ async function decryptTransferData(encryptedHex, privateKey) {
|
|
|
2816
2915
|
}
|
|
2817
2916
|
|
|
2818
2917
|
// src/actions/decrypt.ts
|
|
2819
|
-
async function decryptTokenBalance(config,
|
|
2918
|
+
async function decryptTokenBalance(config, viewerKey) {
|
|
2820
2919
|
const raw = await config.publicClient.readContract({
|
|
2821
2920
|
address: config.address,
|
|
2822
2921
|
abi: confidentialWrapperAbi,
|
|
2823
2922
|
functionName: "encryptedBalanceOf",
|
|
2824
2923
|
args: [config.signer.address]
|
|
2825
2924
|
});
|
|
2826
|
-
const encryptedHex = typeof raw === "string" ? raw : (0,
|
|
2827
|
-
return decryptBalance(encryptedHex,
|
|
2828
|
-
}
|
|
2829
|
-
async function decryptHistoricTransferData(params) {
|
|
2830
|
-
return decryptTransferData(params.encryptedData, params.viewerKey);
|
|
2925
|
+
const encryptedHex = typeof raw === "string" ? raw : (0, import_viem3.bytesToHex)(raw);
|
|
2926
|
+
return decryptBalance(encryptedHex, viewerKey);
|
|
2831
2927
|
}
|
|
2832
2928
|
|
|
2833
2929
|
// src/actions/access.ts
|
|
2834
|
-
var
|
|
2930
|
+
var import_viem5 = require("viem");
|
|
2835
2931
|
|
|
2836
2932
|
// src/utils/viewerKey.ts
|
|
2837
|
-
var
|
|
2933
|
+
var import_viem4 = require("viem");
|
|
2838
2934
|
var import_utils = require("viem/utils");
|
|
2839
2935
|
var import_secp256k12 = require("@noble/curves/secp256k1");
|
|
2840
2936
|
function parsePublicKeyCoordinates(publicKey) {
|
|
@@ -2849,43 +2945,43 @@ function parsePublicKeyCoordinates(publicKey) {
|
|
|
2849
2945
|
}
|
|
2850
2946
|
|
|
2851
2947
|
// src/actions/access.ts
|
|
2852
|
-
async function registerViewerKey(config,
|
|
2853
|
-
const { x, y } = parsePublicKeyCoordinates(
|
|
2854
|
-
const data = (0,
|
|
2948
|
+
async function registerViewerKey(config, publicKey) {
|
|
2949
|
+
const { x, y } = parsePublicKeyCoordinates(publicKey);
|
|
2950
|
+
const data = (0, import_viem5.encodeFunctionData)({
|
|
2855
2951
|
abi: confidentialWrapperAbi,
|
|
2856
2952
|
functionName: "setViewerPublicKey",
|
|
2857
2953
|
args: [{ x, y }]
|
|
2858
2954
|
});
|
|
2859
2955
|
return config.signer.sendTransaction({ to: config.address, data });
|
|
2860
2956
|
}
|
|
2861
|
-
async function authorizeHistoricViewForRange(config,
|
|
2862
|
-
const data = (0,
|
|
2957
|
+
async function authorizeHistoricViewForRange(config, address, fromTimestamp, toTimestamp) {
|
|
2958
|
+
const data = (0, import_viem5.encodeFunctionData)({
|
|
2863
2959
|
abi: confidentialWrapperAbi,
|
|
2864
2960
|
functionName: "authorizeHistoricViewTimeRange",
|
|
2865
|
-
args: [
|
|
2961
|
+
args: [address, fromTimestamp, toTimestamp]
|
|
2866
2962
|
});
|
|
2867
2963
|
return config.signer.sendTransaction({ to: config.address, data });
|
|
2868
2964
|
}
|
|
2869
|
-
async function authorizeHistoricViewForTransfer(config,
|
|
2870
|
-
const data = (0,
|
|
2965
|
+
async function authorizeHistoricViewForTransfer(config, address, transferId) {
|
|
2966
|
+
const data = (0, import_viem5.encodeFunctionData)({
|
|
2871
2967
|
abi: confidentialWrapperAbi,
|
|
2872
2968
|
functionName: "authorizeHistoricViewTransferId",
|
|
2873
|
-
args: [
|
|
2969
|
+
args: [address, transferId]
|
|
2874
2970
|
});
|
|
2875
2971
|
return config.signer.sendTransaction({ to: config.address, data });
|
|
2876
2972
|
}
|
|
2877
|
-
async function revokeHistoricView(config,
|
|
2878
|
-
const data = (0,
|
|
2973
|
+
async function revokeHistoricView(config, address) {
|
|
2974
|
+
const data = (0, import_viem5.encodeFunctionData)({
|
|
2879
2975
|
abi: confidentialWrapperAbi,
|
|
2880
2976
|
functionName: "removeHistoricViewAuth",
|
|
2881
|
-
args: [
|
|
2977
|
+
args: [address]
|
|
2882
2978
|
});
|
|
2883
2979
|
return config.signer.sendTransaction({ to: config.address, data });
|
|
2884
2980
|
}
|
|
2885
|
-
async function requestTransferDecryption(config,
|
|
2886
|
-
const value = await
|
|
2887
|
-
const receipt = await config.publicClient.waitForTransactionReceipt({ hash:
|
|
2888
|
-
const events = (0,
|
|
2981
|
+
async function requestTransferDecryption(config, ctxHash) {
|
|
2982
|
+
const value = await getCtxOperationCost(config);
|
|
2983
|
+
const receipt = await config.publicClient.waitForTransactionReceipt({ hash: ctxHash });
|
|
2984
|
+
const events = (0, import_viem5.parseEventLogs)({
|
|
2889
2985
|
abi: confidentialWrapperAbi,
|
|
2890
2986
|
logs: receipt.logs,
|
|
2891
2987
|
eventName: "EncryptedTransfer"
|
|
@@ -2915,7 +3011,7 @@ async function requestTransferDecryption(config, params) {
|
|
|
2915
3011
|
if (!canDecrypt) {
|
|
2916
3012
|
throw new Error("Viewer is not authorized to decrypt this historic transfer.");
|
|
2917
3013
|
}
|
|
2918
|
-
const data = (0,
|
|
3014
|
+
const data = (0, import_viem5.encodeFunctionData)({
|
|
2919
3015
|
abi: confidentialWrapperAbi,
|
|
2920
3016
|
functionName: "requestDecryptHistoricTransferFor",
|
|
2921
3017
|
args: [encryptedData, viewerAddress]
|
|
@@ -2998,7 +3094,7 @@ var ConfidentialToken = class {
|
|
|
2998
3094
|
this.address = config.address;
|
|
2999
3095
|
this.signer = config.signer;
|
|
3000
3096
|
this.viewerPrivateKey = config.viewerPrivateKey;
|
|
3001
|
-
this.client = (0,
|
|
3097
|
+
this.client = (0, import_viem6.createPublicClient)({ transport: (0, import_viem6.http)(config.rpcUrl) });
|
|
3002
3098
|
this.bite = new import_bite.BITE(config.rpcUrl);
|
|
3003
3099
|
}
|
|
3004
3100
|
get actionConfig() {
|
|
@@ -3058,44 +3154,42 @@ var ConfidentialToken = class {
|
|
|
3058
3154
|
if (!this.viewerPrivateKey) {
|
|
3059
3155
|
throw new Error("Viewer key is required to decrypt balance.");
|
|
3060
3156
|
}
|
|
3061
|
-
return decryptTokenBalance(this.actionConfig,
|
|
3157
|
+
return decryptTokenBalance(this.actionConfig, this.viewerPrivateKey);
|
|
3062
3158
|
}
|
|
3063
3159
|
// --- Standard ERC-20 writes ---
|
|
3064
3160
|
async approve(spender, amount) {
|
|
3065
|
-
return approve(this.actionConfig,
|
|
3161
|
+
return approve(this.actionConfig, spender, amount);
|
|
3066
3162
|
}
|
|
3067
3163
|
// --- Privacy-specific writes ---
|
|
3068
3164
|
transfer(to, amount) {
|
|
3069
|
-
return createCtxPromise(
|
|
3070
|
-
transfer(this.actionConfig, { to, amount }),
|
|
3071
|
-
this.client
|
|
3072
|
-
);
|
|
3165
|
+
return createCtxPromise(transfer(this.actionConfig, to, amount), this.client);
|
|
3073
3166
|
}
|
|
3074
3167
|
// --- Viewer key management ---
|
|
3075
3168
|
async registerViewerPublicKey(publicKey) {
|
|
3076
|
-
return registerViewerKey(this.actionConfig,
|
|
3169
|
+
return registerViewerKey(this.actionConfig, publicKey);
|
|
3077
3170
|
}
|
|
3078
3171
|
async authorizeHistoricViewForRange(address, fromTimestamp, toTimestamp) {
|
|
3079
|
-
return authorizeHistoricViewForRange(
|
|
3172
|
+
return authorizeHistoricViewForRange(
|
|
3173
|
+
this.actionConfig,
|
|
3080
3174
|
address,
|
|
3081
3175
|
fromTimestamp,
|
|
3082
3176
|
toTimestamp
|
|
3083
|
-
|
|
3177
|
+
);
|
|
3084
3178
|
}
|
|
3085
3179
|
async authorizeHistoricViewForTransfer(address, transferId) {
|
|
3086
|
-
return authorizeHistoricViewForTransfer(this.actionConfig,
|
|
3180
|
+
return authorizeHistoricViewForTransfer(this.actionConfig, address, transferId);
|
|
3087
3181
|
}
|
|
3088
3182
|
async revokeHistoricView(address) {
|
|
3089
|
-
return revokeHistoricView(this.actionConfig,
|
|
3183
|
+
return revokeHistoricView(this.actionConfig, address);
|
|
3090
3184
|
}
|
|
3091
3185
|
// --- Decrypt / history ---
|
|
3092
3186
|
async requestTransferDecryption(ctxHash) {
|
|
3093
3187
|
if (!this.viewerPrivateKey) {
|
|
3094
3188
|
throw new Error("Viewer key is required to decrypt transfer data.");
|
|
3095
3189
|
}
|
|
3096
|
-
const txHash = await requestTransferDecryption(this.actionConfig,
|
|
3190
|
+
const txHash = await requestTransferDecryption(this.actionConfig, ctxHash);
|
|
3097
3191
|
const { ctxReceipt } = await waitForCtx(txHash, this.client);
|
|
3098
|
-
const events = (0,
|
|
3192
|
+
const events = (0, import_viem6.parseEventLogs)({
|
|
3099
3193
|
abi: confidentialWrapperAbi,
|
|
3100
3194
|
logs: ctxReceipt.logs,
|
|
3101
3195
|
eventName: "ReEncryptedTransfer"
|
|
@@ -3108,7 +3202,7 @@ var ConfidentialToken = class {
|
|
|
3108
3202
|
if (!encryptedData) {
|
|
3109
3203
|
throw new Error("CTX receipt does not contain a ReEncryptedTransfer event.");
|
|
3110
3204
|
}
|
|
3111
|
-
return
|
|
3205
|
+
return decryptTransferData(encryptedData, this.viewerPrivateKey);
|
|
3112
3206
|
}
|
|
3113
3207
|
};
|
|
3114
3208
|
|
|
@@ -3122,10 +3216,10 @@ var ConfidentialWrapper = class extends ConfidentialToken {
|
|
|
3122
3216
|
});
|
|
3123
3217
|
}
|
|
3124
3218
|
wrap(receiver, amount) {
|
|
3125
|
-
return createCtxPromise(wrap(this.actionConfig,
|
|
3219
|
+
return createCtxPromise(wrap(this.actionConfig, receiver, amount), this.client);
|
|
3126
3220
|
}
|
|
3127
3221
|
unwrap(receiver, amount) {
|
|
3128
|
-
return createCtxPromise(unwrap(this.actionConfig,
|
|
3222
|
+
return createCtxPromise(unwrap(this.actionConfig, receiver, amount), this.client);
|
|
3129
3223
|
}
|
|
3130
3224
|
};
|
|
3131
3225
|
// Annotate the CommonJS export names for ESM import in node:
|