@sabaaa1/common 0.0.4 → 0.0.5
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/_virtual/_commonjsHelpers.cjs +1 -0
- package/_virtual/_commonjsHelpers.mjs +30 -0
- package/_virtual/bn.cjs +1 -0
- package/_virtual/bn.mjs +4 -0
- package/_virtual/bn2.cjs +1 -0
- package/_virtual/bn2.mjs +4 -0
- package/_virtual/common.cjs +1 -0
- package/_virtual/common.mjs +4 -0
- package/_virtual/common2.cjs +1 -0
- package/_virtual/common2.mjs +4 -0
- package/_virtual/hash.cjs +1 -0
- package/_virtual/hash.mjs +4 -0
- package/_virtual/index.cjs +1 -0
- package/_virtual/index.mjs +6 -0
- package/_virtual/index10.cjs +1 -0
- package/_virtual/index10.mjs +6 -0
- package/_virtual/index11.cjs +1 -0
- package/_virtual/index11.mjs +6 -0
- package/_virtual/index12.cjs +1 -0
- package/_virtual/index12.mjs +6 -0
- package/_virtual/index13.cjs +1 -0
- package/_virtual/index13.mjs +6 -0
- package/_virtual/index14.cjs +1 -0
- package/_virtual/index14.mjs +6 -0
- package/_virtual/index15.cjs +1 -0
- package/_virtual/index15.mjs +6 -0
- package/_virtual/index16.cjs +1 -0
- package/_virtual/index16.mjs +6 -0
- package/_virtual/index17.cjs +1 -0
- package/_virtual/index17.mjs +6 -0
- package/_virtual/index18.cjs +1 -0
- package/_virtual/index18.mjs +6 -0
- package/_virtual/index19.cjs +1 -0
- package/_virtual/index19.mjs +6 -0
- package/_virtual/index2.cjs +1 -0
- package/_virtual/index2.mjs +6 -0
- package/_virtual/index20.cjs +1 -0
- package/_virtual/index20.mjs +6 -0
- package/_virtual/index21.cjs +1 -0
- package/_virtual/index21.mjs +4 -0
- package/_virtual/index3.cjs +1 -0
- package/_virtual/index3.mjs +6 -0
- package/_virtual/index4.cjs +1 -0
- package/_virtual/index4.mjs +6 -0
- package/_virtual/index5.cjs +1 -0
- package/_virtual/index5.mjs +6 -0
- package/_virtual/index6.cjs +1 -0
- package/_virtual/index6.mjs +6 -0
- package/_virtual/index7.cjs +1 -0
- package/_virtual/index7.mjs +6 -0
- package/_virtual/index8.cjs +1 -0
- package/_virtual/index8.mjs +6 -0
- package/_virtual/index9.cjs +1 -0
- package/_virtual/index9.mjs +6 -0
- package/_virtual/inherits_browser.cjs +1 -0
- package/_virtual/inherits_browser.mjs +4 -0
- package/_virtual/ripemd.cjs +1 -0
- package/_virtual/ripemd.mjs +4 -0
- package/_virtual/scrypt.cjs +1 -0
- package/_virtual/scrypt.mjs +4 -0
- package/_virtual/sha.cjs +1 -0
- package/_virtual/sha.mjs +4 -0
- package/_virtual/sha3.cjs +1 -0
- package/_virtual/sha3.mjs +4 -0
- package/_virtual/utils.cjs +1 -0
- package/_virtual/utils.mjs +4 -0
- package/_virtual/utils2.cjs +1 -0
- package/_virtual/utils2.mjs +4 -0
- package/data-structures/crypto-keys/keys.cjs +1 -1
- package/data-structures/crypto-keys/keys.mjs +22 -21
- package/package.json +1 -1
- package/providers/WagmiProviderAdapter.cjs +1 -1
- package/providers/WagmiProviderAdapter.mjs +85 -78
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var u=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function f(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function l(e){if(e.__esModule)return e;var r=e.default;if(typeof r=="function"){var t=function o(){return this instanceof o?Reflect.construct(r,arguments,this.constructor):r.apply(this,arguments)};t.prototype=r.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(e).forEach(function(o){var n=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,n.get?n:{enumerable:!0,get:function(){return e[o]}})}),t}exports.commonjsGlobal=u;exports.getAugmentedNamespace=l;exports.getDefaultExportFromCjs=f;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var u = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
2
|
+
function f(e) {
|
|
3
|
+
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
4
|
+
}
|
|
5
|
+
function l(e) {
|
|
6
|
+
if (e.__esModule)
|
|
7
|
+
return e;
|
|
8
|
+
var r = e.default;
|
|
9
|
+
if (typeof r == "function") {
|
|
10
|
+
var t = function o() {
|
|
11
|
+
return this instanceof o ? Reflect.construct(r, arguments, this.constructor) : r.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
t.prototype = r.prototype;
|
|
14
|
+
} else
|
|
15
|
+
t = {};
|
|
16
|
+
return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(e).forEach(function(o) {
|
|
17
|
+
var n = Object.getOwnPropertyDescriptor(e, o);
|
|
18
|
+
Object.defineProperty(t, o, n.get ? n : {
|
|
19
|
+
enumerable: !0,
|
|
20
|
+
get: function() {
|
|
21
|
+
return e[o];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}), t;
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
u as commonjsGlobal,
|
|
28
|
+
l as getAugmentedNamespace,
|
|
29
|
+
f as getDefaultExportFromCjs
|
|
30
|
+
};
|
package/_virtual/bn.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={exports:{}};exports.__module=e;
|
package/_virtual/bn.mjs
ADDED
package/_virtual/bn2.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={exports:{}};exports.__module=e;
|
package/_virtual/bn2.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={};exports.__exports=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={};exports.__exports=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={};exports.__exports=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/address/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/sha2/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/solidity/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/random/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/properties/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/rlp/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/signing-key/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/strings/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/transactions/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/units/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/wallet/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/base64/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/web/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={exports:{}};exports.__module=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/basex/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/bytes/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/hash/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/hdnode/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/json-wallets/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/keccak256/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_commonjsHelpers.cjs"),r=require("../node_modules/@ethersproject/logger/lib.esm/index.cjs"),s=e.getAugmentedNamespace(r);module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={exports:{}};exports.__module=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={};exports.__exports=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={exports:{}};exports.__module=e;
|
package/_virtual/sha.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={};exports.__exports=e;
|
package/_virtual/sha.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={exports:{}};exports.__module=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={};exports.__exports=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={};exports.__exports=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("ethers"),K=require("libsodium-wrappers"),l=require("../../constants/protocol.constants.cjs"),v=require("../../crypto/babyJub.cjs"),c=require("../../crypto/poseidon.cjs"),u=require("./keyUtils.cjs"),g=require("../cacheDevices/AttachableMemoryCacheDevice.cjs")
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("ethers"),K=require("libsodium-wrappers"),l=require("../../constants/protocol.constants.cjs"),v=require("../../crypto/babyJub.cjs"),c=require("../../crypto/poseidon.cjs"),u=require("./keyUtils.cjs"),g=require("../cacheDevices/AttachableMemoryCacheDevice.cjs");require("../../node_modules/ethers/lib/utils.cjs");const h=require("ethers-v6h"),b=require("../../constants/chains.constants.cjs"),d=require("../../_virtual/utils.cjs"),y=new g.AttachableMemoryCacheDevice,S=new g.AttachableMemoryCacheDevice,m={privateKey:"",publicKey:""};class q{signature;constructor(e){this.signature=e}getSignature(){return this.requireSignature(),this.signature}setSignature(e){this.signature=e}requireSignature(){if(!this.signature)throw Error("No signature provided")}verifyMessage(e){return this.requireSignature(),a.utils.verifyMessage(e,this.signature)}getShieldedPrivateKey=()=>(this.requireSignature(),a.ethers.utils.keccak256(this.signature));getShieldedPublicKey=()=>(this.requireSignature(),c.poseidonHash(this.getShieldedPrivateKey()));getAccessKey=()=>(this.requireSignature(),c.poseidonHash(this.getShieldedPrivateKey(),this.getShieldedPublicKey()));static getSignerAddressFromPrivateKey(e){return new h.ethers.Wallet(e).address}static deriveSignerFromNonce(e,t){const r=c.poseidonHash(t,e.getShieldedPrivateKey(),e.getShieldedPublicKey()),s=d.__exports.keccak256(d.__exports.toUtf8Bytes(r));return new h.ethers.Wallet(s)}static async signMessageFromPrivateKey(e,t){const r=new h.ethers.Wallet(e),s=a.utils.isHexString(t)?a.utils.arrayify(t):t;return r.signMessage(s)}static signTypedDataFromPrivateKey(e,t,r,s){return new h.ethers.Wallet(e).signTypedData(t,r,s)}static async authorizeDelegationFromPrivateKey(e,t,r,s){const n=new h.ethers.Wallet(e),i=new h.ethers.JsonRpcProvider(b.networkRegistry[t].fetchRpcUrl);return n.connect(i).authorize({address:r,...s!==void 0&&{nonce:s}})}getWalletSalt=e=>(this.requireSignature(),c.poseidonHash(this.getShieldedPublicKey(),this.getShieldedPrivateKey(),e));getInHinkalAddress=e=>{this.requireSignature();const t=c.poseidonHash(this.getShieldedPrivateKey(),e);return BigInt(t)};getBackendToken=()=>(this.requireSignature(),c.poseidonHash(this.getAccessKey(),this.getShieldedPublicKey()));static getRandomizedStealthPair=y.attach((e,t)=>{const r=v.babyJubInstance(),s=BigInt(t)%l.CIRCOM_P,n=e*s%l.CIRCOM_P,i=r.mulPointEscalar(r.Base8,e),o=r.mulPointEscalar(r.Base8,n),p=[BigInt(r.F.toString(i[0])),BigInt(r.F.toString(i[1]))],P=[BigInt(r.F.toString(o[0])),BigInt(r.F.toString(o[1]))];return{H0:p,H1:P}});static getStealthAddressCompressedPoints=(e,t)=>{const{H0:r,H1:s}=this.getRandomizedStealthPair(e,t),[n,i]=[r,s].map(o=>BigInt(o[1])+2n**255n*u.getCircomSign(o[0]));return{h0:n,h1:i}};static getStealthAddress=S.attach((e,t)=>{const{H0:r,H1:s}=this.getRandomizedStealthPair(e,t),i=[2n*u.getCircomSign(r[0])+u.getCircomSign(s[0]),r[1],s[1]];return c.poseidonHash(...i)});static getStealthAddressWithEKey=(e,t)=>({stealthAddress:this.getStealthAddress(e,t),encryptionKey:this.getEncryptionKeyPair(t).publicKey});static checkSignature=(e,t,r,s)=>{const{h0:n,h1:i}=this.getStealthAddressCompressedPoints(e,s);return t===n&&r===i};static getEncryptionKeyPair=e=>{const t=K.crypto_box_seed_keypair(a.ethers.utils.arrayify(e));return{privateKey:a.ethers.utils.hexlify(t.privateKey),publicKey:a.ethers.utils.hexlify(t.publicKey)}}}exports.EncryptionKeyPairDefaultValue=m;exports.UserKeys=q;exports.stealthAddressCacheDevice=S;exports.stealthPairCacheDevice=y;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { utils as
|
|
2
|
-
import
|
|
1
|
+
import { utils as l, ethers as g } from "ethers";
|
|
2
|
+
import p from "libsodium-wrappers";
|
|
3
3
|
import { CIRCOM_P as d } from "../../constants/protocol.constants.mjs";
|
|
4
|
-
import { babyJubInstance as
|
|
4
|
+
import { babyJubInstance as K } from "../../crypto/babyJub.mjs";
|
|
5
5
|
import { poseidonHash as a } from "../../crypto/poseidon.mjs";
|
|
6
|
-
import { getCircomSign as
|
|
7
|
-
import { AttachableMemoryCacheDevice as
|
|
8
|
-
import
|
|
6
|
+
import { getCircomSign as h } from "./keyUtils.mjs";
|
|
7
|
+
import { AttachableMemoryCacheDevice as y } from "../cacheDevices/AttachableMemoryCacheDevice.mjs";
|
|
8
|
+
import "../../node_modules/ethers/lib/utils.mjs";
|
|
9
9
|
import { ethers as c } from "ethers-v6h";
|
|
10
|
-
import { networkRegistry as
|
|
11
|
-
|
|
10
|
+
import { networkRegistry as P } from "../../constants/chains.constants.mjs";
|
|
11
|
+
import { __exports as u } from "../../_virtual/utils.mjs";
|
|
12
|
+
const v = new y(), f = new y(), R = {
|
|
12
13
|
privateKey: "",
|
|
13
14
|
publicKey: ""
|
|
14
15
|
};
|
|
@@ -28,7 +29,7 @@ class W {
|
|
|
28
29
|
throw Error("No signature provided");
|
|
29
30
|
}
|
|
30
31
|
verifyMessage(e) {
|
|
31
|
-
return this.requireSignature(),
|
|
32
|
+
return this.requireSignature(), l.verifyMessage(e, this.signature);
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* get shielded private key from message signature used to login to the application,
|
|
@@ -52,18 +53,18 @@ class W {
|
|
|
52
53
|
return new c.Wallet(e).address;
|
|
53
54
|
}
|
|
54
55
|
static deriveSignerFromNonce(e, t) {
|
|
55
|
-
const r = a(t, e.getShieldedPrivateKey(), e.getShieldedPublicKey()), i =
|
|
56
|
+
const r = a(t, e.getShieldedPrivateKey(), e.getShieldedPublicKey()), i = u.keccak256(u.toUtf8Bytes(r));
|
|
56
57
|
return new c.Wallet(i);
|
|
57
58
|
}
|
|
58
59
|
static async signMessageFromPrivateKey(e, t) {
|
|
59
|
-
const r = new c.Wallet(e), i =
|
|
60
|
+
const r = new c.Wallet(e), i = l.isHexString(t) ? l.arrayify(t) : t;
|
|
60
61
|
return r.signMessage(i);
|
|
61
62
|
}
|
|
62
63
|
static signTypedDataFromPrivateKey(e, t, r, i) {
|
|
63
64
|
return new c.Wallet(e).signTypedData(t, r, i);
|
|
64
65
|
}
|
|
65
66
|
static async authorizeDelegationFromPrivateKey(e, t, r, i) {
|
|
66
|
-
const n = new c.Wallet(e), s = new c.JsonRpcProvider(
|
|
67
|
+
const n = new c.Wallet(e), s = new c.JsonRpcProvider(P[t].fetchRpcUrl);
|
|
67
68
|
return n.connect(s).authorize({
|
|
68
69
|
address: r,
|
|
69
70
|
...i !== void 0 && { nonce: i }
|
|
@@ -84,18 +85,18 @@ class W {
|
|
|
84
85
|
* @returns accessKey in hexstring with 0x prefixed
|
|
85
86
|
*/
|
|
86
87
|
getBackendToken = () => (this.requireSignature(), a(this.getAccessKey(), this.getShieldedPublicKey()));
|
|
87
|
-
static getRandomizedStealthPair =
|
|
88
|
+
static getRandomizedStealthPair = v.attach(
|
|
88
89
|
(e, t) => {
|
|
89
|
-
const r =
|
|
90
|
-
return { H0:
|
|
90
|
+
const r = K(), i = BigInt(t) % d, n = e * i % d, s = r.mulPointEscalar(r.Base8, e), o = r.mulPointEscalar(r.Base8, n), S = [BigInt(r.F.toString(s[0])), BigInt(r.F.toString(s[1]))], m = [BigInt(r.F.toString(o[0])), BigInt(r.F.toString(o[1]))];
|
|
91
|
+
return { H0: S, H1: m };
|
|
91
92
|
}
|
|
92
93
|
);
|
|
93
94
|
static getStealthAddressCompressedPoints = (e, t) => {
|
|
94
|
-
const { H0: r, H1: i } = this.getRandomizedStealthPair(e, t), [n, s] = [r, i].map((o) => BigInt(o[1]) + 2n ** 255n *
|
|
95
|
+
const { H0: r, H1: i } = this.getRandomizedStealthPair(e, t), [n, s] = [r, i].map((o) => BigInt(o[1]) + 2n ** 255n * h(o[0]));
|
|
95
96
|
return { h0: n, h1: s };
|
|
96
97
|
};
|
|
97
|
-
static getStealthAddress =
|
|
98
|
-
const { H0: r, H1: i } = this.getRandomizedStealthPair(e, t), s = [2n *
|
|
98
|
+
static getStealthAddress = f.attach((e, t) => {
|
|
99
|
+
const { H0: r, H1: i } = this.getRandomizedStealthPair(e, t), s = [2n * h(r[0]) + h(i[0]), r[1], i[1]];
|
|
99
100
|
return a(...s);
|
|
100
101
|
});
|
|
101
102
|
static getStealthAddressWithEKey = (e, t) => ({ stealthAddress: this.getStealthAddress(e, t), encryptionKey: this.getEncryptionKeyPair(t).publicKey });
|
|
@@ -109,7 +110,7 @@ class W {
|
|
|
109
110
|
* and must correspond to 32 bytes
|
|
110
111
|
*/
|
|
111
112
|
static getEncryptionKeyPair = (e) => {
|
|
112
|
-
const t =
|
|
113
|
+
const t = p.crypto_box_seed_keypair(g.utils.arrayify(e));
|
|
113
114
|
return {
|
|
114
115
|
privateKey: g.utils.hexlify(t.privateKey),
|
|
115
116
|
publicKey: g.utils.hexlify(t.publicKey)
|
|
@@ -119,6 +120,6 @@ class W {
|
|
|
119
120
|
export {
|
|
120
121
|
R as EncryptionKeyPairDefaultValue,
|
|
121
122
|
W as UserKeys,
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
f as stealthAddressCacheDevice,
|
|
124
|
+
v as stealthPairCacheDevice
|
|
124
125
|
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../constants/chains.constants.cjs"),i=require("../error-handling/error-codes.constants.cjs"),o=require("ethers"),g=require("wagmi"),c=require("../functions/web3/getContractMetadata.cjs"),h=require("../node_modules/@wagmi/core/dist/esm/actions/disconnect.cjs"),u=require("../node_modules/@wagmi/core/dist/esm/actions/reconnect.cjs"),w=require("../node_modules/@wagmi/core/dist/esm/actions/connect.cjs"),l=require("../node_modules/@wagmi/core/dist/esm/actions/signMessage.cjs"),f=require("../node_modules/@wagmi/core/dist/esm/actions/switchChain.cjs"),C=require("../node_modules/@wagmi/core/dist/esm/actions/getAccount.cjs"),v=require("../node_modules/@wagmi/core/dist/esm/actions/watchAccount.cjs"),I=require("../node_modules/@wagmi/core/dist/esm/actions/watchChainId.cjs");class a{connector;chainId;originalProvider;fetchProvider;signer;chainEventListener;config;unsubscribeFns=[];initConnector(t){this.connector=t}getSigner(){if(!this.signer)throw new Error("No Signer In Provider Adapter");return this.signer}requireConnector(){if(!this.connector)throw Error("No Connector In Provider Adapter")}initConfig(t){this.config=t}async init(t){this.requireConnector(),t&&(this.chainId=t),this.originalProvider=await this.connector.getProvider(),this.fetchProvider=this.createFetchProvider()??this.originalProvider,this.fetchProvider===this.originalProvider&&console.warn("fetchProvider not available");const r=await this.connector.getProvider(),e=await this.connector.getAccounts();this.signer=await this.walletClientToSigner({transport:r,account:e[0]},this.chainId)}async disconnectFromConnector(){if(!this.config)throw new Error("No Config In Provider Adapter");this.release(),await h.disconnect(this.config)}async connectToConnector(t){if(!this.config)throw new Error("No Config In Provider Adapter");if(t.id==="walletConnect")try{await u.reconnect(this.config,{connectors:[t]}),await h.disconnect(this.config)}catch{}try{return(await w.connect(this.config,{connector:t})).chainId}catch(r){if(r instanceof g.ConnectorAlreadyConnectedError)return t.getChainId();let e=i.transactionErrorCodes.CONNECTION_FAILED;throw r?.code===4001&&(e=i.UserFriendlyErrorCodes.YOU_CANCELED_REQUEST),new Error(e)}}async waitForTransaction(t,r){if((await this.fetchProvider?.waitForTransaction(t,r))?.status)return!0;throw Error(i.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED)}async signMessage(t){if(!this.config)throw new Error("No Config In Provider Adapter");const r=await l.signMessage(this.config,{message:t});if(!r)throw new Error(i.transactionErrorCodes.SIGNING_FAILED);if(r.includes("error"))throw new Error(i.transactionErrorCodes.SIGNATURE_UNSUPPORTED_PERSONAL_SIGN);return r}async signTypedData(t,r,e){return this.signer._signTypedData(t,r,e)}getSelectedNetwork=()=>{if(!this.chainId)throw new Error("Illegal state: no chaindId");return n.networkRegistry[this.chainId]};async switchNetwork(t){if(!this.config)throw new Error("No Config In Provider Adapter");return f.switchChain(this.config,{chainId:t.chainId})}createFetchProvider(){try{const r=n.networkRegistry[this.chainId]?.fetchRpcUrl;return r?r.includes("wss")?new o.providers.WebSocketProvider(r):new o.providers.StaticJsonRpcProvider(r):void 0}catch(t){console.log("create Fetch Provider error",t);return}}async getAddress(){if(!this.config)throw new Error("No Config In Provider Adapter");const{address:t}=C.getAccount(this.config);if(!t)throw new Error("IllegalState");return o.utils.getAddress(t)}setChainEventListener(t){if(!this.config)throw new Error("No Config In Provider Adapter");this.chainEventListener=t,this.chainEventListener&&(this.unsubscribeFns.push(v.watchAccount(this.config,{onChange:({address:r},{address:e})=>{if(!this.chainEventListener){console.warn("chainEventListener is not set");return}console.log("Account changed"),r!==e&&(console.log("Account changed"),this.chainEventListener.onAccountChanged())}})),this.unsubscribeFns.push(I.watchChainId(this.config,{onChange:r=>{if(!this.chainEventListener){console.warn("chainEventListener is not set");return}console.log("Chain ID changed!",r),this.chainEventListener.onChainChanged(r)}})))}onAccountChanged(){return this.init()}onChainChanged(t){return this.init(t)}release(){this.removeListeners()}removeListeners(){this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[]}parseChainIdParam(t){const r=t??this.chainId;if(!r)throw new Error("No chainId provided in context");return r}getContractMetadata(t,r){const e=this.parseChainIdParam(r);return c.getContractMetadata(t,e)}getContract(t,r=void 0,e){const s=this.parseChainIdParam(e);return c.getContract(t,s,r)}getContractWithSigner(t,r=void 0){if(!this.signer)throw new Error("IllegalState: no signer");return this.getContract(t,r).connect(this.signer)}getContractWithFetcher(t,r=void 0){if(!this.fetchProvider)throw new Error("fetchProvider not initialized");return this.getContract(t,r).connect(this.fetchProvider)}getContractWithFetcherForEthereum(t,r=void 0){const e=this.chainId===n.chainIds.localhost&&n.localhostNetwork===n.chainIds.ethMainnet?n.chainIds.localhost:n.chainIds.ethMainnet;return c.getContractWithFetcherByChainId(e,t,r)}async sendTransaction(t){if(!this.signer)throw new Error("IllegalState: no signer");return await this.signer.sendTransaction(t)}async connectAndPatchProvider(t){return await this.connectToConnector(t)}isPermitterAvailable(){return!!this.getSelectedNetwork()?.contractData?.permitterAddress}async getGasPrice(){const t=await this.fetchProvider?.getGasPrice();if(!t)throw Error("Could not fetch gas price in getGasPrice");return t.toBigInt()}async walletClientToSigner(t,r){const{account:e,transport:s}=t,d={chainId:r,name:""};return new o.providers.Web3Provider(s,d).getSigner(e)}switchAccount(){throw new Error("Method not implemented.")}}const E=new a,P=()=>new a;exports.WagmiProviderAdapter=a;exports.default=P;exports.wagmiProviderAdapter=E;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { networkRegistry as c, chainIds as n, localhostNetwork as g } from "../constants/chains.constants.mjs";
|
|
2
|
-
import { transactionErrorCodes as i, UserFriendlyErrorCodes as
|
|
3
|
-
import { providers as s, utils as
|
|
2
|
+
import { transactionErrorCodes as i, UserFriendlyErrorCodes as f } from "../error-handling/error-codes.constants.mjs";
|
|
3
|
+
import { providers as s, utils as w } from "ethers";
|
|
4
4
|
import { ConnectorAlreadyConnectedError as l } from "wagmi";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { getContractMetadata as u, getContract as v, getContractWithFetcherByChainId as C } from "../functions/web3/getContractMetadata.mjs";
|
|
6
|
+
import { disconnect as a } from "../node_modules/@wagmi/core/dist/esm/actions/disconnect.mjs";
|
|
7
|
+
import { reconnect as p } from "../node_modules/@wagmi/core/dist/esm/actions/reconnect.mjs";
|
|
8
|
+
import { connect as I } from "../node_modules/@wagmi/core/dist/esm/actions/connect.mjs";
|
|
9
|
+
import { signMessage as E } from "../node_modules/@wagmi/core/dist/esm/actions/signMessage.mjs";
|
|
10
|
+
import { switchChain as P } from "../node_modules/@wagmi/core/dist/esm/actions/switchChain.mjs";
|
|
11
|
+
import { getAccount as m } from "../node_modules/@wagmi/core/dist/esm/actions/getAccount.mjs";
|
|
12
|
+
import { watchAccount as A } from "../node_modules/@wagmi/core/dist/esm/actions/watchAccount.mjs";
|
|
13
|
+
import { watchChainId as N } from "../node_modules/@wagmi/core/dist/esm/actions/watchChainId.mjs";
|
|
7
14
|
class h {
|
|
8
15
|
connector;
|
|
9
16
|
chainId;
|
|
@@ -13,8 +20,8 @@ class h {
|
|
|
13
20
|
chainEventListener;
|
|
14
21
|
config;
|
|
15
22
|
unsubscribeFns = [];
|
|
16
|
-
initConnector(
|
|
17
|
-
this.connector =
|
|
23
|
+
initConnector(r) {
|
|
24
|
+
this.connector = r;
|
|
18
25
|
}
|
|
19
26
|
getSigner() {
|
|
20
27
|
if (!this.signer)
|
|
@@ -25,104 +32,104 @@ class h {
|
|
|
25
32
|
if (!this.connector)
|
|
26
33
|
throw Error("No Connector In Provider Adapter");
|
|
27
34
|
}
|
|
28
|
-
initConfig(
|
|
29
|
-
this.config =
|
|
35
|
+
initConfig(r) {
|
|
36
|
+
this.config = r;
|
|
30
37
|
}
|
|
31
|
-
async init(
|
|
32
|
-
this.requireConnector(),
|
|
33
|
-
const
|
|
34
|
-
this.signer = await this.walletClientToSigner({ transport:
|
|
38
|
+
async init(r) {
|
|
39
|
+
this.requireConnector(), r && (this.chainId = r), this.originalProvider = await this.connector.getProvider(), this.fetchProvider = this.createFetchProvider() ?? this.originalProvider, this.fetchProvider === this.originalProvider && console.warn("fetchProvider not available");
|
|
40
|
+
const t = await this.connector.getProvider(), e = await this.connector.getAccounts();
|
|
41
|
+
this.signer = await this.walletClientToSigner({ transport: t, account: e[0] }, this.chainId);
|
|
35
42
|
}
|
|
36
43
|
async disconnectFromConnector() {
|
|
37
44
|
if (!this.config)
|
|
38
45
|
throw new Error("No Config In Provider Adapter");
|
|
39
46
|
this.release(), await a(this.config);
|
|
40
47
|
}
|
|
41
|
-
async connectToConnector(
|
|
48
|
+
async connectToConnector(r) {
|
|
42
49
|
if (!this.config)
|
|
43
50
|
throw new Error("No Config In Provider Adapter");
|
|
44
|
-
if (
|
|
51
|
+
if (r.id === "walletConnect")
|
|
45
52
|
try {
|
|
46
|
-
await
|
|
53
|
+
await p(this.config, { connectors: [r] }), await a(this.config);
|
|
47
54
|
} catch {
|
|
48
55
|
}
|
|
49
56
|
try {
|
|
50
|
-
return (await
|
|
51
|
-
} catch (
|
|
52
|
-
if (
|
|
53
|
-
return
|
|
57
|
+
return (await I(this.config, { connector: r })).chainId;
|
|
58
|
+
} catch (t) {
|
|
59
|
+
if (t instanceof l)
|
|
60
|
+
return r.getChainId();
|
|
54
61
|
let e = i.CONNECTION_FAILED;
|
|
55
|
-
throw
|
|
62
|
+
throw t?.code === 4001 && (e = f.YOU_CANCELED_REQUEST), new Error(e);
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
|
-
async waitForTransaction(
|
|
59
|
-
if ((await this.fetchProvider?.waitForTransaction(
|
|
65
|
+
async waitForTransaction(r, t) {
|
|
66
|
+
if ((await this.fetchProvider?.waitForTransaction(r, t))?.status)
|
|
60
67
|
return !0;
|
|
61
68
|
throw Error(i.TRANSACTION_NOT_CONFIRMED);
|
|
62
69
|
}
|
|
63
|
-
async signMessage(
|
|
70
|
+
async signMessage(r) {
|
|
64
71
|
if (!this.config)
|
|
65
72
|
throw new Error("No Config In Provider Adapter");
|
|
66
|
-
const
|
|
67
|
-
if (!
|
|
73
|
+
const t = await E(this.config, { message: r });
|
|
74
|
+
if (!t)
|
|
68
75
|
throw new Error(i.SIGNING_FAILED);
|
|
69
|
-
if (
|
|
76
|
+
if (t.includes("error"))
|
|
70
77
|
throw new Error(i.SIGNATURE_UNSUPPORTED_PERSONAL_SIGN);
|
|
71
|
-
return
|
|
78
|
+
return t;
|
|
72
79
|
}
|
|
73
|
-
async signTypedData(
|
|
74
|
-
return this.signer._signTypedData(
|
|
80
|
+
async signTypedData(r, t, e) {
|
|
81
|
+
return this.signer._signTypedData(r, t, e);
|
|
75
82
|
}
|
|
76
83
|
getSelectedNetwork = () => {
|
|
77
84
|
if (!this.chainId)
|
|
78
85
|
throw new Error("Illegal state: no chaindId");
|
|
79
86
|
return c[this.chainId];
|
|
80
87
|
};
|
|
81
|
-
async switchNetwork(
|
|
88
|
+
async switchNetwork(r) {
|
|
82
89
|
if (!this.config)
|
|
83
90
|
throw new Error("No Config In Provider Adapter");
|
|
84
|
-
return
|
|
85
|
-
chainId:
|
|
91
|
+
return P(this.config, {
|
|
92
|
+
chainId: r.chainId
|
|
86
93
|
});
|
|
87
94
|
}
|
|
88
95
|
createFetchProvider() {
|
|
89
96
|
try {
|
|
90
|
-
const
|
|
91
|
-
return
|
|
92
|
-
} catch (
|
|
93
|
-
console.log("create Fetch Provider error",
|
|
97
|
+
const t = c[this.chainId]?.fetchRpcUrl;
|
|
98
|
+
return t ? t.includes("wss") ? new s.WebSocketProvider(t) : new s.StaticJsonRpcProvider(t) : void 0;
|
|
99
|
+
} catch (r) {
|
|
100
|
+
console.log("create Fetch Provider error", r);
|
|
94
101
|
return;
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
104
|
async getAddress() {
|
|
98
105
|
if (!this.config)
|
|
99
106
|
throw new Error("No Config In Provider Adapter");
|
|
100
|
-
const { address:
|
|
101
|
-
if (!
|
|
107
|
+
const { address: r } = m(this.config);
|
|
108
|
+
if (!r)
|
|
102
109
|
throw new Error("IllegalState");
|
|
103
|
-
return
|
|
110
|
+
return w.getAddress(r);
|
|
104
111
|
}
|
|
105
|
-
setChainEventListener(
|
|
112
|
+
setChainEventListener(r) {
|
|
106
113
|
if (!this.config)
|
|
107
114
|
throw new Error("No Config In Provider Adapter");
|
|
108
|
-
this.chainEventListener =
|
|
109
|
-
|
|
110
|
-
onChange: ({ address:
|
|
115
|
+
this.chainEventListener = r, this.chainEventListener && (this.unsubscribeFns.push(
|
|
116
|
+
A(this.config, {
|
|
117
|
+
onChange: ({ address: t }, { address: e }) => {
|
|
111
118
|
if (!this.chainEventListener) {
|
|
112
119
|
console.warn("chainEventListener is not set");
|
|
113
120
|
return;
|
|
114
121
|
}
|
|
115
|
-
console.log("Account changed"),
|
|
122
|
+
console.log("Account changed"), t !== e && (console.log("Account changed"), this.chainEventListener.onAccountChanged());
|
|
116
123
|
}
|
|
117
124
|
})
|
|
118
125
|
), this.unsubscribeFns.push(
|
|
119
|
-
|
|
120
|
-
onChange: (
|
|
126
|
+
N(this.config, {
|
|
127
|
+
onChange: (t) => {
|
|
121
128
|
if (!this.chainEventListener) {
|
|
122
129
|
console.warn("chainEventListener is not set");
|
|
123
130
|
return;
|
|
124
131
|
}
|
|
125
|
-
console.log("Chain ID changed!",
|
|
132
|
+
console.log("Chain ID changed!", t), this.chainEventListener.onChainChanged(t);
|
|
126
133
|
}
|
|
127
134
|
})
|
|
128
135
|
));
|
|
@@ -130,63 +137,63 @@ class h {
|
|
|
130
137
|
onAccountChanged() {
|
|
131
138
|
return this.init();
|
|
132
139
|
}
|
|
133
|
-
onChainChanged(
|
|
134
|
-
return this.init(
|
|
140
|
+
onChainChanged(r) {
|
|
141
|
+
return this.init(r);
|
|
135
142
|
}
|
|
136
143
|
release() {
|
|
137
144
|
this.removeListeners();
|
|
138
145
|
}
|
|
139
146
|
removeListeners() {
|
|
140
|
-
this.unsubscribeFns.forEach((
|
|
147
|
+
this.unsubscribeFns.forEach((r) => r()), this.unsubscribeFns = [];
|
|
141
148
|
}
|
|
142
|
-
parseChainIdParam(
|
|
143
|
-
const
|
|
144
|
-
if (!
|
|
149
|
+
parseChainIdParam(r) {
|
|
150
|
+
const t = r ?? this.chainId;
|
|
151
|
+
if (!t)
|
|
145
152
|
throw new Error("No chainId provided in context");
|
|
146
|
-
return
|
|
153
|
+
return t;
|
|
147
154
|
}
|
|
148
|
-
getContractMetadata(
|
|
149
|
-
const e = this.parseChainIdParam(
|
|
150
|
-
return
|
|
155
|
+
getContractMetadata(r, t) {
|
|
156
|
+
const e = this.parseChainIdParam(t);
|
|
157
|
+
return u(r, e);
|
|
151
158
|
}
|
|
152
|
-
getContract(
|
|
159
|
+
getContract(r, t = void 0, e) {
|
|
153
160
|
const o = this.parseChainIdParam(e);
|
|
154
|
-
return
|
|
161
|
+
return v(r, o, t);
|
|
155
162
|
}
|
|
156
|
-
getContractWithSigner(
|
|
163
|
+
getContractWithSigner(r, t = void 0) {
|
|
157
164
|
if (!this.signer)
|
|
158
165
|
throw new Error("IllegalState: no signer");
|
|
159
|
-
return this.getContract(
|
|
166
|
+
return this.getContract(r, t).connect(this.signer);
|
|
160
167
|
}
|
|
161
|
-
getContractWithFetcher(
|
|
168
|
+
getContractWithFetcher(r, t = void 0) {
|
|
162
169
|
if (!this.fetchProvider)
|
|
163
170
|
throw new Error("fetchProvider not initialized");
|
|
164
|
-
return this.getContract(
|
|
171
|
+
return this.getContract(r, t).connect(this.fetchProvider);
|
|
165
172
|
}
|
|
166
|
-
getContractWithFetcherForEthereum(
|
|
173
|
+
getContractWithFetcherForEthereum(r, t = void 0) {
|
|
167
174
|
const e = this.chainId === n.localhost && g === n.ethMainnet ? n.localhost : n.ethMainnet;
|
|
168
|
-
return
|
|
175
|
+
return C(e, r, t);
|
|
169
176
|
}
|
|
170
|
-
async sendTransaction(
|
|
177
|
+
async sendTransaction(r) {
|
|
171
178
|
if (!this.signer)
|
|
172
179
|
throw new Error("IllegalState: no signer");
|
|
173
|
-
return await this.signer.sendTransaction(
|
|
180
|
+
return await this.signer.sendTransaction(r);
|
|
174
181
|
}
|
|
175
|
-
async connectAndPatchProvider(
|
|
176
|
-
return await this.connectToConnector(
|
|
182
|
+
async connectAndPatchProvider(r) {
|
|
183
|
+
return await this.connectToConnector(r);
|
|
177
184
|
}
|
|
178
185
|
isPermitterAvailable() {
|
|
179
186
|
return !!this.getSelectedNetwork()?.contractData?.permitterAddress;
|
|
180
187
|
}
|
|
181
188
|
async getGasPrice() {
|
|
182
|
-
const
|
|
183
|
-
if (!
|
|
189
|
+
const r = await this.fetchProvider?.getGasPrice();
|
|
190
|
+
if (!r)
|
|
184
191
|
throw Error("Could not fetch gas price in getGasPrice");
|
|
185
|
-
return
|
|
192
|
+
return r.toBigInt();
|
|
186
193
|
}
|
|
187
|
-
async walletClientToSigner(
|
|
188
|
-
const { account: e, transport: o } =
|
|
189
|
-
chainId:
|
|
194
|
+
async walletClientToSigner(r, t) {
|
|
195
|
+
const { account: e, transport: o } = r, d = {
|
|
196
|
+
chainId: t,
|
|
190
197
|
name: ""
|
|
191
198
|
};
|
|
192
199
|
return new s.Web3Provider(o, d).getSigner(e);
|
|
@@ -195,9 +202,9 @@ class h {
|
|
|
195
202
|
throw new Error("Method not implemented.");
|
|
196
203
|
}
|
|
197
204
|
}
|
|
198
|
-
const
|
|
205
|
+
const q = new h(), B = () => new h();
|
|
199
206
|
export {
|
|
200
207
|
h as WagmiProviderAdapter,
|
|
201
|
-
|
|
202
|
-
|
|
208
|
+
B as default,
|
|
209
|
+
q as wagmiProviderAdapter
|
|
203
210
|
};
|