@gardenfi/core 2.0.18 → 2.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -6343,7 +6343,9 @@ class ln {
|
|
|
6343
6343
|
);
|
|
6344
6344
|
const n = r ?? await this.signer.getAddress(), { tx: i, usedUtxos: s } = await this._tempBuildRawTx(
|
|
6345
6345
|
n
|
|
6346
|
-
)
|
|
6346
|
+
);
|
|
6347
|
+
console.log("utxos :", s);
|
|
6348
|
+
const o = this.leafHash(
|
|
6347
6349
|
1
|
|
6348
6350
|
/* REDEEM */
|
|
6349
6351
|
), a = s.map((p) => p.value), c = vr(this.getOutputScript(), s.length), l = re.Transaction.SIGHASH_DEFAULT;
|
|
@@ -9930,23 +9932,23 @@ Lr.ECPairFactory = Ud;
|
|
|
9930
9932
|
const Cd = /* @__PURE__ */ ju(ef);
|
|
9931
9933
|
class fi extends va {
|
|
9932
9934
|
get isInitialized() {
|
|
9933
|
-
return !!this.
|
|
9935
|
+
return !!this.digestKey;
|
|
9934
9936
|
}
|
|
9935
9937
|
constructor(t, r) {
|
|
9936
|
-
super(), this.
|
|
9938
|
+
super(), this.digestKey = t, this.walletClient = r;
|
|
9937
9939
|
}
|
|
9938
|
-
static
|
|
9940
|
+
static fromDigestKey(t) {
|
|
9939
9941
|
return new fi(er(t));
|
|
9940
9942
|
}
|
|
9941
9943
|
static fromWalletClient(t) {
|
|
9942
9944
|
return new fi(void 0, t);
|
|
9943
9945
|
}
|
|
9944
9946
|
async initialize() {
|
|
9945
|
-
if (this.
|
|
9946
|
-
const t = await this.
|
|
9947
|
+
if (this.digestKey) return ne("Already initialized");
|
|
9948
|
+
const t = await this.deriveDigestKeyFromWalletClient();
|
|
9947
9949
|
return t.error ? j(t.error) : (this.emit("initialized", !0), ne("Initialized"));
|
|
9948
9950
|
}
|
|
9949
|
-
async
|
|
9951
|
+
async deriveDigestKeyFromWalletClient() {
|
|
9950
9952
|
if (!this.walletClient) return j("No walletClient found");
|
|
9951
9953
|
if (!this.walletClient.account) return j("No account found");
|
|
9952
9954
|
try {
|
|
@@ -9974,20 +9976,20 @@ class fi extends va {
|
|
|
9974
9976
|
Nonce: 1n
|
|
9975
9977
|
}
|
|
9976
9978
|
});
|
|
9977
|
-
return this.
|
|
9979
|
+
return this.digestKey = er(kn(t)), this.emit("initialized", !0), ne(this.digestKey);
|
|
9978
9980
|
} catch (t) {
|
|
9979
9981
|
return j("Failed to initialize: " + t);
|
|
9980
9982
|
}
|
|
9981
9983
|
}
|
|
9982
|
-
async
|
|
9983
|
-
if (!this.
|
|
9984
|
+
async getDigestKey() {
|
|
9985
|
+
if (!this.digestKey && !this.walletClient)
|
|
9984
9986
|
return j("No private key or wallet client found");
|
|
9985
|
-
if (!this.
|
|
9986
|
-
const t = await this.
|
|
9987
|
+
if (!this.digestKey && this.walletClient) {
|
|
9988
|
+
const t = await this.deriveDigestKeyFromWalletClient();
|
|
9987
9989
|
if (t.error)
|
|
9988
9990
|
return j(t.error);
|
|
9989
9991
|
}
|
|
9990
|
-
return this.
|
|
9992
|
+
return this.digestKey ? ne(this.digestKey) : j("No private key found");
|
|
9991
9993
|
}
|
|
9992
9994
|
async generateSecret(t) {
|
|
9993
9995
|
const r = await this.signMessage(t);
|
|
@@ -9996,12 +9998,12 @@ class fi extends va {
|
|
|
9996
9998
|
return ne({ secret: n, secretHash: i });
|
|
9997
9999
|
}
|
|
9998
10000
|
async signMessage(t) {
|
|
9999
|
-
if (!this.
|
|
10000
|
-
const l = await this.
|
|
10001
|
+
if (!this.digestKey) {
|
|
10002
|
+
const l = await this.getDigestKey();
|
|
10001
10003
|
if (l.error) return j(l.error);
|
|
10002
|
-
this.
|
|
10004
|
+
this.digestKey = l.val;
|
|
10003
10005
|
}
|
|
10004
|
-
const r = Cd(ir), n = "Garden.fi" + t.toString(), i = Buffer.from(n, "utf8"), s = kn(i), o = Buffer.from(er(this.
|
|
10006
|
+
const r = Cd(ir), n = "Garden.fi" + t.toString(), i = Buffer.from(n, "utf8"), s = kn(i), o = Buffer.from(er(this.digestKey), "hex");
|
|
10005
10007
|
if (o.length !== 32)
|
|
10006
10008
|
return j("Invalid private key length. Expected 32 bytes.");
|
|
10007
10009
|
const c = r.fromPrivateKey(o).sign(Buffer.from(er(s), "hex"));
|
|
@@ -10055,7 +10057,7 @@ class q1 extends va {
|
|
|
10055
10057
|
async initializeSMandBTCWallet() {
|
|
10056
10058
|
if (this._secretManager.isInitialized && this._btcWallet)
|
|
10057
10059
|
return ne(this._btcWallet);
|
|
10058
|
-
const t = await this._secretManager.
|
|
10060
|
+
const t = await this._secretManager.getDigestKey();
|
|
10059
10061
|
if (t.error) return j(t.error);
|
|
10060
10062
|
const r = new _u(Cu(this.environment));
|
|
10061
10063
|
return this._btcWallet = vu.fromPrivateKey(t.val, r), ne(this._btcWallet);
|
|
@@ -3,15 +3,15 @@ import { EventBroker } from '@gardenfi/utils';
|
|
|
3
3
|
import { ISecretManager, SecretManagerEvents } from './secretManager.types';
|
|
4
4
|
|
|
5
5
|
export declare class SecretManager extends EventBroker<SecretManagerEvents> implements ISecretManager {
|
|
6
|
-
private
|
|
6
|
+
private digestKey?;
|
|
7
7
|
private walletClient?;
|
|
8
8
|
get isInitialized(): boolean;
|
|
9
9
|
private constructor();
|
|
10
|
-
static
|
|
10
|
+
static fromDigestKey(digestKey: string): SecretManager;
|
|
11
11
|
static fromWalletClient(walletClient: WalletClient): SecretManager;
|
|
12
12
|
initialize(): Promise<import('@catalogfi/utils').Result<never, string> | import('@catalogfi/utils').Result<string, never>>;
|
|
13
|
-
private
|
|
14
|
-
|
|
13
|
+
private deriveDigestKeyFromWalletClient;
|
|
14
|
+
getDigestKey(): Promise<import('@catalogfi/utils').Result<never, string> | import('@catalogfi/utils').Result<string, never>>;
|
|
15
15
|
generateSecret(nonce: string): Promise<import('@catalogfi/utils').Result<never, string> | import('@catalogfi/utils').Result<{
|
|
16
16
|
secret: `0x${string}`;
|
|
17
17
|
secretHash: `0x${string}`;
|
|
@@ -16,12 +16,12 @@ export interface ISecretManager extends EventBroker<SecretManagerEvents> {
|
|
|
16
16
|
*/
|
|
17
17
|
initialize: () => AsyncResult<string, string>;
|
|
18
18
|
/**
|
|
19
|
-
* Generates a new
|
|
20
|
-
* If the
|
|
21
|
-
* Else, it will generate a new
|
|
22
|
-
* @returns
|
|
19
|
+
* Generates a new digest key.
|
|
20
|
+
* If the digest key already exists, it will return the existing digest key.
|
|
21
|
+
* Else, it will generate a new digest key by hashing a signature generated by signing a message with the wallet client.
|
|
22
|
+
* @returns digest key
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
getDigestKey: () => AsyncResult<string, string>;
|
|
25
25
|
/**
|
|
26
26
|
* Generates secret and secretHash by signing the nonce.
|
|
27
27
|
* Secret is generated by hashing the signature and secretHash is generated by hashing the secret.
|