@bsv/wallet-toolbox 1.6.18 → 1.6.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/mobile/out/src/Wallet.d.ts +4 -0
- package/mobile/out/src/Wallet.d.ts.map +1 -1
- package/mobile/out/src/Wallet.js +62 -21
- package/mobile/out/src/Wallet.js.map +1 -1
- package/mobile/package-lock.json +2 -2
- package/mobile/package.json +1 -1
- package/out/src/Wallet.d.ts +4 -0
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js +62 -21
- package/out/src/Wallet.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/Wallet.ts +87 -28
package/package.json
CHANGED
package/src/Wallet.ts
CHANGED
|
@@ -615,6 +615,15 @@ export class Wallet implements WalletInterface, ProtoWallet {
|
|
|
615
615
|
return r
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
+
/** 2-minute cache of trust settings for identity resolution paths */
|
|
619
|
+
private _trustSettingsCache?: {
|
|
620
|
+
expiresAt: number
|
|
621
|
+
trustSettings: Awaited<ReturnType<WalletSettingsManager['get']>>['trustSettings']
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/** 2-minute cache of queryOverlay() results keyed by normalized query */
|
|
625
|
+
private _overlayCache: Map<string, { expiresAt: number; value: unknown }> = new Map()
|
|
626
|
+
|
|
618
627
|
async discoverByIdentityKey(
|
|
619
628
|
args: DiscoverByIdentityKeyArgs,
|
|
620
629
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
@@ -622,21 +631,42 @@ export class Wallet implements WalletInterface, ProtoWallet {
|
|
|
622
631
|
validateOriginator(originator)
|
|
623
632
|
this.validateAuthAndArgs(args, validateDiscoverByIdentityKeyArgs)
|
|
624
633
|
|
|
625
|
-
const
|
|
626
|
-
const
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
634
|
+
const TTL_MS = 2 * 60 * 1000
|
|
635
|
+
const now = Date.now()
|
|
636
|
+
|
|
637
|
+
// --- trustSettings cache (2 minutes) ---
|
|
638
|
+
let trustSettings =
|
|
639
|
+
this._trustSettingsCache && this._trustSettingsCache.expiresAt > now
|
|
640
|
+
? this._trustSettingsCache.trustSettings
|
|
641
|
+
: undefined
|
|
642
|
+
|
|
643
|
+
if (!trustSettings) {
|
|
644
|
+
const settings = await this.settingsManager.get()
|
|
645
|
+
trustSettings = settings.trustSettings
|
|
646
|
+
this._trustSettingsCache = { trustSettings, expiresAt: now + TTL_MS }
|
|
638
647
|
}
|
|
639
|
-
|
|
648
|
+
|
|
649
|
+
const certifiers = trustSettings.trustedCertifiers.map(c => c.identityKey).sort()
|
|
650
|
+
|
|
651
|
+
// --- queryOverlay cache (2 minutes) ---
|
|
652
|
+
const cacheKey = JSON.stringify({
|
|
653
|
+
fn: 'discoverByIdentityKey',
|
|
654
|
+
identityKey: args.identityKey,
|
|
655
|
+
certifiers
|
|
656
|
+
})
|
|
657
|
+
|
|
658
|
+
let cached = this._overlayCache.get(cacheKey)
|
|
659
|
+
if (!cached || cached.expiresAt <= now) {
|
|
660
|
+
const value = await queryOverlay({ identityKey: args.identityKey, certifiers }, this.lookupResolver)
|
|
661
|
+
cached = { value, expiresAt: now + TTL_MS }
|
|
662
|
+
this._overlayCache.set(cacheKey, cached)
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if (!cached.value) {
|
|
666
|
+
return { totalCertificates: 0, certificates: [] }
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
return transformVerifiableCertificatesWithTrust(trustSettings, cached.value as any)
|
|
640
670
|
}
|
|
641
671
|
|
|
642
672
|
async discoverByAttributes(
|
|
@@ -646,21 +676,50 @@ export class Wallet implements WalletInterface, ProtoWallet {
|
|
|
646
676
|
validateOriginator(originator)
|
|
647
677
|
this.validateAuthAndArgs(args, validateDiscoverByAttributesArgs)
|
|
648
678
|
|
|
649
|
-
const
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
}
|
|
679
|
+
const TTL_MS = 2 * 60 * 1000
|
|
680
|
+
const now = Date.now()
|
|
681
|
+
|
|
682
|
+
// --- trustSettings cache (2 minutes) ---
|
|
683
|
+
let trustSettings =
|
|
684
|
+
this._trustSettingsCache && this._trustSettingsCache.expiresAt > now
|
|
685
|
+
? this._trustSettingsCache.trustSettings
|
|
686
|
+
: undefined
|
|
687
|
+
|
|
688
|
+
if (!trustSettings) {
|
|
689
|
+
const settings = await this.settingsManager.get()
|
|
690
|
+
trustSettings = settings.trustSettings
|
|
691
|
+
this._trustSettingsCache = { trustSettings, expiresAt: now + TTL_MS }
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const certifiers = trustSettings.trustedCertifiers.map(c => c.identityKey).sort()
|
|
695
|
+
|
|
696
|
+
// Normalize attributes for a stable cache key.
|
|
697
|
+
// If attributes is an object, sort its top-level keys; if it's an array, sort a shallow copy.
|
|
698
|
+
let attributesKey: unknown = args.attributes
|
|
699
|
+
if (args.attributes && typeof args.attributes === 'object') {
|
|
700
|
+
const keys = Object.keys(args.attributes as Record<string, unknown>).sort()
|
|
701
|
+
attributesKey = JSON.stringify(args.attributes, keys)
|
|
662
702
|
}
|
|
663
|
-
|
|
703
|
+
|
|
704
|
+
// --- queryOverlay cache (2 minutes) ---
|
|
705
|
+
const cacheKey = JSON.stringify({
|
|
706
|
+
fn: 'discoverByAttributes',
|
|
707
|
+
attributes: attributesKey,
|
|
708
|
+
certifiers
|
|
709
|
+
})
|
|
710
|
+
|
|
711
|
+
let cached = this._overlayCache.get(cacheKey)
|
|
712
|
+
if (!cached || cached.expiresAt <= now) {
|
|
713
|
+
const value = await queryOverlay({ attributes: args.attributes, certifiers }, this.lookupResolver)
|
|
714
|
+
cached = { value, expiresAt: now + TTL_MS }
|
|
715
|
+
this._overlayCache.set(cacheKey, cached)
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
if (!cached.value) {
|
|
719
|
+
return { totalCertificates: 0, certificates: [] }
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
return transformVerifiableCertificatesWithTrust(trustSettings, cached.value as any)
|
|
664
723
|
}
|
|
665
724
|
|
|
666
725
|
verifyReturnedTxidOnly(beef: Beef, knownTxids?: string[]): Beef {
|