@flapsdk/vault-runtime 0.1.44-next.0 → 0.1.44
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 +50 -41
- package/{chunk-ZLF6YGWQ.js → chunk-LSLJIASB.js} +127 -42
- package/chunk-LSLJIASB.js.map +1 -0
- package/{chunk-BIRAO6LU.js → chunk-SFUJ26PT.js} +68 -350
- package/chunk-SFUJ26PT.js.map +1 -0
- package/{chunk-5DU4W4CK.js → chunk-ZH7JPICS.js} +4 -563
- package/chunk-ZH7JPICS.js.map +1 -0
- package/host-client.d.mts +2 -4
- package/host-client.js +3 -3
- package/host.d.mts +5 -5
- package/host.js +1 -1
- package/{hostRuntimeConfig-5ZZT8uC7.d.mts → hostRuntimeConfig-BUyUPuZu.d.mts} +1 -1
- package/package.json +4 -6
- package/runtime-contract.json +4 -13
- package/sdk.d.mts +6 -33
- package/sdk.js +8 -10
- package/sdk.js.map +1 -1
- package/server.d.mts +3 -3
- package/{txError-CjQVWypm.d.mts → txError-B0s03tgD.d.mts} +1 -1
- package/{types-kDMLRchJ.d.mts → types-Cs2dnHsa.d.mts} +13 -128
- package/ui.d.mts +2 -74
- package/ui.js +1 -1
- package/chunk-5DU4W4CK.js.map +0 -1
- package/chunk-BIRAO6LU.js.map +0 -1
- package/chunk-ZLF6YGWQ.js.map +0 -1
- package/maplibre-gl-KTPWJHIW.js +0 -26453
- package/maplibre-gl-KTPWJHIW.js.map +0 -1
- package/runtime-map/LICENSE.maplibre.txt +0 -116
- package/runtime-map/maplibre-6.15.0-worker.mjs +0 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveManifestBinding } from './chunk-B4WKI3EW.js';
|
|
2
2
|
import { resolveIpfsImageUrls } from './chunk-GY7YY67I.js';
|
|
3
|
-
import { toFunctionSelector, parseAbi, isHex, decodeFunctionData, encodeFunctionData, isAddress, keccak256 } from 'viem';
|
|
3
|
+
import { toFunctionSelector, parseAbi, isHex, decodeFunctionData, encodeFunctionData, isAddress, keccak256, prepareEncodeFunctionData } from 'viem';
|
|
4
4
|
|
|
5
5
|
var bad = (ok, reason) => {
|
|
6
6
|
if (!ok) throw new Error(`app-wallet/${reason}`);
|
|
@@ -39,14 +39,52 @@ function permissions(input) {
|
|
|
39
39
|
return { definition: structuredClone(input), writes, reads };
|
|
40
40
|
}
|
|
41
41
|
var hasDynamicBytes = (parameter) => /^bytes(?:\[|$)/.test(parameter.type) || parameter.components?.some(hasDynamicBytes);
|
|
42
|
-
var
|
|
42
|
+
var MAX_FIXED_BYTES_PER_CALL = 4096;
|
|
43
43
|
function hasOnlyFields(value, keys) {
|
|
44
44
|
return value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).every((key) => keys.includes(key));
|
|
45
45
|
}
|
|
46
|
+
function parseResolvedWriteConstraints(root, resolved, writes) {
|
|
47
|
+
const constraints = /* @__PURE__ */ new Map();
|
|
48
|
+
if (resolved.writeConstraints !== void 0) {
|
|
49
|
+
const rules = resolved.writeConstraints;
|
|
50
|
+
bad(Array.isArray(rules) && rules.length > 0 && rules.length <= writes.length, "invalid-write-constraints");
|
|
51
|
+
bad(root.codeHash && resolved.codeHash, "missing-code-hash");
|
|
52
|
+
for (const rule of rules) {
|
|
53
|
+
bad(hasOnlyFields(rule, ["selector", "fixedBytes", "valueWei"]), "invalid-write-constraints");
|
|
54
|
+
bad(typeof rule.selector === "string" && rule.selector.length === 10 && /^0x[0-9a-f]{8}$/i.test(rule.selector), "invalid-constrained-selector");
|
|
55
|
+
const selector = rule.selector.toLowerCase();
|
|
56
|
+
const entry = writes.find((method) => toFunctionSelector(method) === selector);
|
|
57
|
+
bad(entry && !constraints.has(selector), "invalid-constrained-selector");
|
|
58
|
+
bad(Array.isArray(rule.fixedBytes) && rule.fixedBytes.length > 0 && rule.fixedBytes.length <= entry.inputs.length, "invalid-fixed-bytes");
|
|
59
|
+
const fixedBytes = /* @__PURE__ */ new Map();
|
|
60
|
+
let totalBytes = 0;
|
|
61
|
+
for (const bound of rule.fixedBytes) {
|
|
62
|
+
bad(hasOnlyFields(bound, ["index", "length"]) && Number.isSafeInteger(bound.index) && bound.index >= 0 && entry.inputs[bound.index]?.type === "bytes" && !fixedBytes.has(bound.index), "invalid-fixed-bytes");
|
|
63
|
+
bad(Number.isSafeInteger(bound.length) && bound.length > 0 && bound.length <= MAX_FIXED_BYTES_PER_CALL, "invalid-fixed-bytes");
|
|
64
|
+
fixedBytes.set(bound.index, bound.length);
|
|
65
|
+
totalBytes += bound.length;
|
|
66
|
+
}
|
|
67
|
+
bad(totalBytes <= MAX_FIXED_BYTES_PER_CALL, "invalid-fixed-bytes");
|
|
68
|
+
let valueWei;
|
|
69
|
+
if (rule.valueWei !== void 0) {
|
|
70
|
+
bad(entry.stateMutability === "payable" && typeof rule.valueWei === "string" && /^(?:0|[1-9][0-9]{0,77})$/.test(rule.valueWei), "invalid-exact-value");
|
|
71
|
+
valueWei = BigInt(rule.valueWei);
|
|
72
|
+
bad(String(valueWei) === rule.valueWei && valueWei <= BigInt(resolved.maxValueWei), "invalid-exact-value");
|
|
73
|
+
}
|
|
74
|
+
constraints.set(selector, { fixedBytes, valueWei });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const method of writes) {
|
|
78
|
+
const fixedBytes = constraints.get(toFunctionSelector(method))?.fixedBytes;
|
|
79
|
+
bad(method.inputs.every((input, index) => !hasDynamicBytes(input) || input.type === "bytes" && fixedBytes?.has(index)), "nested-calldata-not-allowed");
|
|
80
|
+
}
|
|
81
|
+
return constraints;
|
|
82
|
+
}
|
|
83
|
+
var common = ["id", "allow", "read", "maxValueWei", "approvalSpenders", "maxApprovalWei", "codeHash"];
|
|
46
84
|
function identity(input, keys) {
|
|
47
85
|
bad(hasOnlyFields(input, keys), "unknown-field");
|
|
48
86
|
bad(identifier(input.id), "invalid-id");
|
|
49
|
-
bad(input.codeHash === void 0 || /^0x[0-9a-fA-F]{64}$/.test(input.codeHash), "invalid-code-hash");
|
|
87
|
+
bad(input.codeHash === void 0 || typeof input.codeHash === "string" && input.codeHash.length === 66 && /^0x[0-9a-fA-F]{64}$/.test(input.codeHash), "invalid-code-hash");
|
|
50
88
|
}
|
|
51
89
|
function checkPresaleApproval(declaration, resolved) {
|
|
52
90
|
if (declaration === void 0) return;
|
|
@@ -70,7 +108,7 @@ function parseAppWalletContracts(value) {
|
|
|
70
108
|
const policy = permissions(input);
|
|
71
109
|
bad(input.resolvedContracts === void 0 || Array.isArray(input.resolvedContracts) && input.resolvedContracts.length <= 8, "invalid-resolvers");
|
|
72
110
|
const resolved = (input.resolvedContracts ?? []).map((item) => {
|
|
73
|
-
identity(item, [...common, "resolver"]);
|
|
111
|
+
identity(item, [...common, "resolver", "writeConstraints"]);
|
|
74
112
|
bad(!ids.has(item.id), "duplicate-resolver");
|
|
75
113
|
ids.add(item.id);
|
|
76
114
|
bad(typeof item.resolver === "string" && item.resolver.length <= 2048, "invalid-resolver");
|
|
@@ -78,8 +116,8 @@ function parseAppWalletContracts(value) {
|
|
|
78
116
|
const resolver = entries[0];
|
|
79
117
|
bad(entries.length === 1 && resolver.type === "function" && ["view", "pure"].includes(resolver.stateMutability) && resolver.outputs.length === 1 && resolver.outputs[0].type === "address" && resolver.inputs.length <= 32, "invalid-resolver");
|
|
80
118
|
const parsed = permissions(item);
|
|
81
|
-
|
|
82
|
-
return { ...parsed, resolver };
|
|
119
|
+
const writeConstraints = parseResolvedWriteConstraints(input, item, parsed.writes);
|
|
120
|
+
return { ...parsed, resolver, ...writeConstraints.size ? { writeConstraints } : {} };
|
|
83
121
|
});
|
|
84
122
|
checkPresaleApproval(input.presaleApproval, resolved);
|
|
85
123
|
return { ...policy, resolved };
|
|
@@ -136,12 +174,22 @@ function createAppWalletContracts(runtime, chainId, manifest) {
|
|
|
136
174
|
}
|
|
137
175
|
function checkFunction(request, policy, write) {
|
|
138
176
|
requireRule(request.abi && request.functionName, "invalid-call");
|
|
139
|
-
const
|
|
177
|
+
const parameters = { abi: request.abi, functionName: request.functionName, args: request.args };
|
|
178
|
+
const value = request.value ?? 0n;
|
|
179
|
+
const prepared = write && policy.writeConstraints?.size ? prepareEncodeFunctionData(parameters) : void 0;
|
|
180
|
+
const constraint = prepared && policy.writeConstraints?.get(prepared.functionName);
|
|
181
|
+
if (constraint) {
|
|
182
|
+
for (const [index, length] of constraint.fixedBytes) {
|
|
183
|
+
const bytes = request.args?.[index];
|
|
184
|
+
requireRule(typeof bytes === "string" && bytes.length === 2 + 2 * length && bytes.startsWith("0x") && !/[^a-f0-9]/i.test(bytes.slice(2)), "fixed-bytes-length-mismatch");
|
|
185
|
+
}
|
|
186
|
+
requireRule(constraint.valueWei === void 0 || value === constraint.valueWei, "exact-value-mismatch");
|
|
187
|
+
}
|
|
188
|
+
const data = encodeFunctionData({ ...parameters, ...prepared });
|
|
140
189
|
const selector = data.slice(0, 10);
|
|
141
190
|
const entry = (write ? policy.writes : policy.reads).find((f) => toFunctionSelector(f) === selector);
|
|
142
191
|
requireRule(entry, "selector-not-allowed");
|
|
143
192
|
requireRule(encodeFunctionData({ abi: [entry], functionName: entry.name, args: request.args }) === data, "abi-mismatch");
|
|
144
|
-
const value = request.value ?? 0n;
|
|
145
193
|
requireRule(value >= 0n && (value === 0n || entry.stateMutability === "payable" && policy.definition.maxValueWei && value <= BigInt(policy.definition.maxValueWei)), "value-not-allowed");
|
|
146
194
|
if (write && selector === ERC20_APPROVE_SELECTOR) {
|
|
147
195
|
requireRule(policy.definition.approvalSpenders?.some((a) => same(a, request.args?.[0])), "spender-not-allowed");
|
|
@@ -182,7 +230,7 @@ function createAppWalletContracts(runtime, chainId, manifest) {
|
|
|
182
230
|
requireRule(same(address2, record.address), "resolved-target-changed");
|
|
183
231
|
} else if (write) await checkCode(address2, policy);
|
|
184
232
|
const { selector, call } = checkFunction({ ...prepared.request, address: address2 }, policy, write);
|
|
185
|
-
if (write && hasPresaleApproval && selector === PRESALE_CONTRIBUTE_QUOTE_SELECTOR) {
|
|
233
|
+
if (write && hasPresaleApproval && (record?.root ?? root)?.definition.presaleApproval !== void 0 && selector === PRESALE_CONTRIBUTE_QUOTE_SELECTOR) {
|
|
186
234
|
requireRule(account, "presale-account-unavailable");
|
|
187
235
|
const { token, amount } = await resolvePresaleQuote(record, address2, call.args?.[0]);
|
|
188
236
|
const allowance = await runtime.readContract(chainId, { address: token, abi: quoteAbi, functionName: "allowance", args: [account, address2] });
|
|
@@ -312,7 +360,8 @@ function createIpfsTextReader({ fetchImpl = fetch, timeoutMs = 8e3 } = {}) {
|
|
|
312
360
|
var FSI_QUERY_PREFIX = "https://bsc-debug.butterfly.army/fsi/v1";
|
|
313
361
|
var FSI_QUERY_PREFIXES = Object.freeze([
|
|
314
362
|
"https://fsi.taxed.fun/fsi/v1",
|
|
315
|
-
FSI_QUERY_PREFIX
|
|
363
|
+
FSI_QUERY_PREFIX,
|
|
364
|
+
"https://bsc-testnet-debug.butterfly.army/fsi/v1"
|
|
316
365
|
]);
|
|
317
366
|
var FSI_ORIGINS = new Set(FSI_QUERY_PREFIXES.map((prefix) => new URL(prefix).origin));
|
|
318
367
|
var FSI_PATH = "/fsi/v1";
|
|
@@ -382,11 +431,13 @@ async function readFsiJson(endpoints, path, params, fetchImpl = fetch) {
|
|
|
382
431
|
// src/sdk/contractWriteFees.ts
|
|
383
432
|
var MAX_CONTRACT_WRITE_GAS = 5000000n;
|
|
384
433
|
var MAX_GAS_PRICE_MULTIPLIER = 2n;
|
|
385
|
-
|
|
434
|
+
var BSC_MAX_CONTRACT_WRITE_GAS = 15000000n;
|
|
435
|
+
async function resolveSafeContractWriteFeeOverrides(request, getNetworkGasPrice, chainId) {
|
|
386
436
|
if (request.gas !== void 0) {
|
|
387
437
|
if (request.gas <= 0n) throw new Error("Contract write gas must be greater than zero.");
|
|
388
|
-
|
|
389
|
-
|
|
438
|
+
const maximumGas = chainId === 56 || chainId === 97 ? BSC_MAX_CONTRACT_WRITE_GAS : MAX_CONTRACT_WRITE_GAS;
|
|
439
|
+
if (request.gas > maximumGas) {
|
|
440
|
+
throw new Error(`Contract write gas must not exceed ${maximumGas.toString()}.`);
|
|
390
441
|
}
|
|
391
442
|
}
|
|
392
443
|
if (request.gasPrice !== void 0) {
|
|
@@ -486,7 +537,7 @@ function createFlapChainSdk(runtime, input) {
|
|
|
486
537
|
const prepared = appPolicy?.snapshot(request);
|
|
487
538
|
const snapshot = prepared?.request ?? structuredClone(request);
|
|
488
539
|
assertValue(snapshot.value);
|
|
489
|
-
const fees = await resolveSafeContractWriteFeeOverrides(snapshot, () => runtime.getGasPrice(chainId));
|
|
540
|
+
const fees = await resolveSafeContractWriteFeeOverrides(snapshot, () => runtime.getGasPrice(chainId), chainId);
|
|
490
541
|
const { call, presaleQuoteToken } = appPolicy && prepared ? await appPolicy.validate(prepared, true, account) : { call: contractRequest(snapshot), presaleQuoteToken: void 0 };
|
|
491
542
|
writeAccount(account);
|
|
492
543
|
return { call: { ...call, ...fees, account, value: snapshot.value }, prepared, presaleQuoteToken };
|
|
@@ -607,339 +658,6 @@ function createFlapChainSdk(runtime, input) {
|
|
|
607
658
|
};
|
|
608
659
|
}
|
|
609
660
|
|
|
610
|
-
// src/sdk/deviceSensors.ts
|
|
611
|
-
var DEVICE_SENSORS_VERSION = 1;
|
|
612
|
-
var ALL = ["location", "motion", "orientation"];
|
|
613
|
-
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
614
|
-
var finite = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
615
|
-
var nonnegative = (value) => {
|
|
616
|
-
const number = finite(value);
|
|
617
|
-
return number !== null && number >= 0 ? number : null;
|
|
618
|
-
};
|
|
619
|
-
var boundedTimeout = (value) => Math.min(12e4, Math.max(1, nonnegative(value) ?? DEFAULT_TIMEOUT_MS));
|
|
620
|
-
function browserEnvironment() {
|
|
621
|
-
if (typeof window === "undefined" || typeof document === "undefined" || typeof navigator === "undefined") return void 0;
|
|
622
|
-
return {
|
|
623
|
-
secure: window.isSecureContext === true,
|
|
624
|
-
window,
|
|
625
|
-
document,
|
|
626
|
-
geolocation: navigator.geolocation,
|
|
627
|
-
setTimeout: (callback, milliseconds) => window.setTimeout(callback, milliseconds),
|
|
628
|
-
clearTimeout: (id) => window.clearTimeout(id),
|
|
629
|
-
now: Date.now
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
function locationData(value, now) {
|
|
633
|
-
const coords = value?.coords;
|
|
634
|
-
const latitude = finite(coords?.latitude), longitude = finite(coords?.longitude), accuracy = nonnegative(coords?.accuracy);
|
|
635
|
-
if (latitude === null || Math.abs(latitude) > 90 || longitude === null || Math.abs(longitude) > 180 || accuracy === null) return null;
|
|
636
|
-
return { latitude, longitude, accuracy, altitude: finite(coords.altitude), altitudeAccuracy: nonnegative(coords.altitudeAccuracy), heading: finite(coords.heading), speed: nonnegative(coords.speed), timestamp: finite(value.timestamp) ?? now };
|
|
637
|
-
}
|
|
638
|
-
function vector(value) {
|
|
639
|
-
const result = { x: finite(value?.x), y: finite(value?.y), z: finite(value?.z) };
|
|
640
|
-
return Object.values(result).some((item) => item !== null) ? result : null;
|
|
641
|
-
}
|
|
642
|
-
function motionData(value, now) {
|
|
643
|
-
const acceleration = vector(value?.acceleration), accelerationIncludingGravity = vector(value?.accelerationIncludingGravity);
|
|
644
|
-
const rotation = { alpha: finite(value?.rotationRate?.alpha), beta: finite(value?.rotationRate?.beta), gamma: finite(value?.rotationRate?.gamma) };
|
|
645
|
-
const rotationRate = Object.values(rotation).some((item) => item !== null) ? rotation : null;
|
|
646
|
-
if (!acceleration && !accelerationIncludingGravity && !rotationRate) return null;
|
|
647
|
-
return { acceleration, accelerationIncludingGravity, rotationRate, interval: nonnegative(value?.interval), timestamp: now };
|
|
648
|
-
}
|
|
649
|
-
function orientationData(value, now) {
|
|
650
|
-
const alpha = finite(value?.alpha), beta = finite(value?.beta), gamma = finite(value?.gamma);
|
|
651
|
-
return alpha === null && beta === null && gamma === null ? null : { alpha, beta, gamma, absolute: value?.absolute === true, timestamp: now };
|
|
652
|
-
}
|
|
653
|
-
function inactiveSensor(status, mode) {
|
|
654
|
-
const snapshot = Object.freeze({ status, permission: "unknown", data: null, mode });
|
|
655
|
-
return { getSnapshot: () => snapshot, subscribe: () => () => {
|
|
656
|
-
}, request: () => Promise.resolve(snapshot), stop() {
|
|
657
|
-
} };
|
|
658
|
-
}
|
|
659
|
-
function createBrowserChannel(kind, declared, resolveEnvironment) {
|
|
660
|
-
if (!declared) return inactiveSensor("not-declared", "real");
|
|
661
|
-
let state = { status: "idle", permission: "unknown", data: null, mode: "real" };
|
|
662
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
663
|
-
let generation = 0;
|
|
664
|
-
let pending;
|
|
665
|
-
let environment;
|
|
666
|
-
let options = {};
|
|
667
|
-
let watchId;
|
|
668
|
-
let timer;
|
|
669
|
-
let eventListener;
|
|
670
|
-
let visibilityListener;
|
|
671
|
-
let abortListener;
|
|
672
|
-
let shouldResume = false;
|
|
673
|
-
let sawInvalidData = false;
|
|
674
|
-
let sessionActive = false;
|
|
675
|
-
const eventName = kind === "motion" ? "devicemotion" : "deviceorientation";
|
|
676
|
-
function update(next) {
|
|
677
|
-
state = { ...state, ...next };
|
|
678
|
-
for (const listener of listeners) listener();
|
|
679
|
-
}
|
|
680
|
-
function settle() {
|
|
681
|
-
const task = pending;
|
|
682
|
-
pending = void 0;
|
|
683
|
-
task?.resolve(state);
|
|
684
|
-
}
|
|
685
|
-
function clearTimer() {
|
|
686
|
-
if (timer !== void 0) environment?.clearTimeout(timer);
|
|
687
|
-
timer = void 0;
|
|
688
|
-
}
|
|
689
|
-
function detachHardware() {
|
|
690
|
-
clearTimer();
|
|
691
|
-
if (watchId !== void 0) environment?.geolocation?.clearWatch(watchId);
|
|
692
|
-
watchId = void 0;
|
|
693
|
-
if (eventListener) environment?.window.removeEventListener(eventName, eventListener);
|
|
694
|
-
eventListener = void 0;
|
|
695
|
-
}
|
|
696
|
-
function cleanup() {
|
|
697
|
-
generation += 1;
|
|
698
|
-
detachHardware();
|
|
699
|
-
if (visibilityListener) environment?.document.removeEventListener("visibilitychange", visibilityListener);
|
|
700
|
-
visibilityListener = void 0;
|
|
701
|
-
if (abortListener) options.signal?.removeEventListener("abort", abortListener);
|
|
702
|
-
abortListener = void 0;
|
|
703
|
-
sessionActive = false;
|
|
704
|
-
shouldResume = false;
|
|
705
|
-
}
|
|
706
|
-
function finish(status, permission = state.permission) {
|
|
707
|
-
cleanup();
|
|
708
|
-
update({ status, permission, data: null });
|
|
709
|
-
settle();
|
|
710
|
-
}
|
|
711
|
-
function stop() {
|
|
712
|
-
const hadWork = sessionActive || Boolean(pending);
|
|
713
|
-
cleanup();
|
|
714
|
-
update({ status: hadWork ? "cancelled" : "idle", data: null });
|
|
715
|
-
settle();
|
|
716
|
-
}
|
|
717
|
-
function guard(env) {
|
|
718
|
-
if (!env) return "unsupported";
|
|
719
|
-
if (!env.secure) return "insecure";
|
|
720
|
-
const features = kind === "location" ? ["geolocation"] : ["accelerometer", "gyroscope"];
|
|
721
|
-
const policy = env.document.permissionsPolicy ?? env.document.featurePolicy;
|
|
722
|
-
try {
|
|
723
|
-
if (policy && features.some((feature) => !policy.allowsFeature(feature))) return "policy-blocked";
|
|
724
|
-
} catch (error) {
|
|
725
|
-
if (error?.name === "SecurityError") return "policy-blocked";
|
|
726
|
-
}
|
|
727
|
-
if (kind === "location" ? !env.geolocation : !(kind === "motion" ? env.window.DeviceMotionEvent : env.window.DeviceOrientationEvent)) return "unsupported";
|
|
728
|
-
return null;
|
|
729
|
-
}
|
|
730
|
-
function accept(raw, token) {
|
|
731
|
-
if (token !== generation || !sessionActive) return;
|
|
732
|
-
const data = kind === "location" ? locationData(raw, environment.now()) : kind === "motion" ? motionData(raw, environment.now()) : orientationData(raw, environment.now());
|
|
733
|
-
if (!data) {
|
|
734
|
-
sawInvalidData = true;
|
|
735
|
-
return;
|
|
736
|
-
}
|
|
737
|
-
clearTimer();
|
|
738
|
-
update({ status: "active", permission: "granted", data });
|
|
739
|
-
settle();
|
|
740
|
-
if (kind === "location" && !options.watch) {
|
|
741
|
-
cleanup();
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
function startHardware() {
|
|
745
|
-
const env = environment;
|
|
746
|
-
if (env.document.visibilityState === "hidden") {
|
|
747
|
-
shouldResume = true;
|
|
748
|
-
update({ status: "paused", data: null });
|
|
749
|
-
settle();
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
const token = generation;
|
|
753
|
-
sawInvalidData = false;
|
|
754
|
-
update({ status: "requesting", data: null });
|
|
755
|
-
timer = env.setTimeout(() => {
|
|
756
|
-
if (token === generation) finish(sawInvalidData ? "unavailable" : "timeout");
|
|
757
|
-
}, boundedTimeout(options.timeoutMs));
|
|
758
|
-
try {
|
|
759
|
-
if (kind === "location") {
|
|
760
|
-
const failed = (error) => {
|
|
761
|
-
if (token !== generation || !sessionActive) return;
|
|
762
|
-
const status = error?.code === 1 ? "denied" : error?.code === 3 ? "timeout" : "unavailable";
|
|
763
|
-
finish(status, status === "denied" ? "denied" : state.permission);
|
|
764
|
-
};
|
|
765
|
-
const geoOptions = { enableHighAccuracy: options.enableHighAccuracy === true, maximumAge: nonnegative(options.maximumAge) ?? 0, timeout: boundedTimeout(options.timeoutMs) };
|
|
766
|
-
if (options.watch) {
|
|
767
|
-
const id = env.geolocation.watchPosition((value) => accept(value, token), failed, geoOptions);
|
|
768
|
-
if (token === generation && sessionActive) watchId = id;
|
|
769
|
-
else env.geolocation.clearWatch(id);
|
|
770
|
-
} else env.geolocation.getCurrentPosition((value) => accept(value, token), failed, geoOptions);
|
|
771
|
-
} else {
|
|
772
|
-
eventListener = (value) => accept(value, token);
|
|
773
|
-
env.window.addEventListener(eventName, eventListener);
|
|
774
|
-
}
|
|
775
|
-
} catch (error) {
|
|
776
|
-
if (token === generation) finish(error?.name === "SecurityError" ? "policy-blocked" : "unavailable");
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
function observeSession() {
|
|
780
|
-
const env = environment;
|
|
781
|
-
visibilityListener = () => {
|
|
782
|
-
if (!sessionActive) return;
|
|
783
|
-
if (env.document.visibilityState === "hidden") {
|
|
784
|
-
generation += 1;
|
|
785
|
-
detachHardware();
|
|
786
|
-
shouldResume = true;
|
|
787
|
-
update({ status: "paused", data: null });
|
|
788
|
-
settle();
|
|
789
|
-
} else if (shouldResume) {
|
|
790
|
-
shouldResume = false;
|
|
791
|
-
if (state.permission === "granted") startHardware();
|
|
792
|
-
else finish("paused");
|
|
793
|
-
}
|
|
794
|
-
};
|
|
795
|
-
env.document.addEventListener("visibilitychange", visibilityListener);
|
|
796
|
-
if (options.signal) {
|
|
797
|
-
abortListener = () => finish("cancelled");
|
|
798
|
-
options.signal.addEventListener("abort", abortListener, { once: true });
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
function request(requestOptions = {}) {
|
|
802
|
-
if (pending) return pending.promise;
|
|
803
|
-
if (state.status === "active" && (kind !== "location" || options.watch && requestOptions.watch)) return Promise.resolve(state);
|
|
804
|
-
cleanup();
|
|
805
|
-
options = { ...requestOptions };
|
|
806
|
-
let blocked;
|
|
807
|
-
try {
|
|
808
|
-
environment = resolveEnvironment();
|
|
809
|
-
blocked = guard(environment);
|
|
810
|
-
} catch (error) {
|
|
811
|
-
blocked = error?.name === "SecurityError" ? "policy-blocked" : "unavailable";
|
|
812
|
-
}
|
|
813
|
-
if (blocked) {
|
|
814
|
-
update({ status: blocked, data: null });
|
|
815
|
-
return Promise.resolve(state);
|
|
816
|
-
}
|
|
817
|
-
if (options.signal?.aborted) {
|
|
818
|
-
update({ status: "cancelled", data: null });
|
|
819
|
-
return Promise.resolve(state);
|
|
820
|
-
}
|
|
821
|
-
if (environment.document.visibilityState === "hidden") {
|
|
822
|
-
update({ status: "paused", data: null });
|
|
823
|
-
return Promise.resolve(state);
|
|
824
|
-
}
|
|
825
|
-
sessionActive = true;
|
|
826
|
-
let resolve;
|
|
827
|
-
const promise = new Promise((done) => {
|
|
828
|
-
resolve = done;
|
|
829
|
-
});
|
|
830
|
-
pending = { promise, resolve };
|
|
831
|
-
update({ status: "requesting", data: null });
|
|
832
|
-
observeSession();
|
|
833
|
-
const token = generation;
|
|
834
|
-
if (kind === "location") startHardware();
|
|
835
|
-
else {
|
|
836
|
-
const constructor = kind === "motion" ? environment.window.DeviceMotionEvent : environment.window.DeviceOrientationEvent;
|
|
837
|
-
try {
|
|
838
|
-
const permission = constructor?.requestPermission?.();
|
|
839
|
-
if (permission) {
|
|
840
|
-
Promise.resolve(permission).then((result) => {
|
|
841
|
-
if (token !== generation || !sessionActive) return;
|
|
842
|
-
if (result !== "granted") {
|
|
843
|
-
finish("denied", "denied");
|
|
844
|
-
return;
|
|
845
|
-
}
|
|
846
|
-
update({ permission: "granted" });
|
|
847
|
-
startHardware();
|
|
848
|
-
}, (error) => {
|
|
849
|
-
if (token === generation && sessionActive) finish(error?.name === "NotAllowedError" ? "denied" : "unavailable");
|
|
850
|
-
});
|
|
851
|
-
} else startHardware();
|
|
852
|
-
} catch (error) {
|
|
853
|
-
if (token === generation) finish(error?.name === "NotAllowedError" ? "denied" : "unavailable");
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
return promise;
|
|
857
|
-
}
|
|
858
|
-
return {
|
|
859
|
-
getSnapshot: () => state,
|
|
860
|
-
subscribe(listener) {
|
|
861
|
-
listeners.add(listener);
|
|
862
|
-
let subscribed = true;
|
|
863
|
-
return () => {
|
|
864
|
-
if (!subscribed) return;
|
|
865
|
-
subscribed = false;
|
|
866
|
-
listeners.delete(listener);
|
|
867
|
-
if (listeners.size === 0 && sessionActive) stop();
|
|
868
|
-
};
|
|
869
|
-
},
|
|
870
|
-
request,
|
|
871
|
-
stop
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
function createBrowserDeviceSensors(options = {}) {
|
|
875
|
-
const allowed = new Set(options.capabilities ?? ALL);
|
|
876
|
-
const environment = () => typeof options.environment === "function" ? options.environment() : options.environment ?? browserEnvironment();
|
|
877
|
-
const location = createBrowserChannel("location", allowed.has("location"), environment);
|
|
878
|
-
const motion = createBrowserChannel("motion", allowed.has("motion"), environment);
|
|
879
|
-
const orientation = createBrowserChannel("orientation", allowed.has("orientation"), environment);
|
|
880
|
-
return { version: DEVICE_SENSORS_VERSION, mode: "real", location, motion, orientation, dispose() {
|
|
881
|
-
location.stop();
|
|
882
|
-
motion.stop();
|
|
883
|
-
orientation.stop();
|
|
884
|
-
} };
|
|
885
|
-
}
|
|
886
|
-
function createMockDeviceSensors(options = {}) {
|
|
887
|
-
const allowed = new Set(options.capabilities ?? ALL);
|
|
888
|
-
function channel(capability, data) {
|
|
889
|
-
if (!allowed.has(capability)) return inactiveSensor("not-declared", "mock");
|
|
890
|
-
let state = { status: "idle", permission: "unknown", data: null, mode: "mock" };
|
|
891
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
892
|
-
const update = (next) => {
|
|
893
|
-
state = next;
|
|
894
|
-
for (const listener of listeners) listener();
|
|
895
|
-
};
|
|
896
|
-
return {
|
|
897
|
-
getSnapshot: () => state,
|
|
898
|
-
subscribe(listener) {
|
|
899
|
-
listeners.add(listener);
|
|
900
|
-
return () => {
|
|
901
|
-
listeners.delete(listener);
|
|
902
|
-
};
|
|
903
|
-
},
|
|
904
|
-
request(requestOptions) {
|
|
905
|
-
const outcome = options.outcome ?? "granted";
|
|
906
|
-
const status = requestOptions?.signal?.aborted ? "cancelled" : outcome === "granted" ? "active" : outcome;
|
|
907
|
-
update({ status, permission: status === "active" ? "granted" : status === "denied" ? "denied" : "unknown", data: status === "active" ? data : null, mode: "mock" });
|
|
908
|
-
return Promise.resolve(state);
|
|
909
|
-
},
|
|
910
|
-
stop() {
|
|
911
|
-
update({ ...state, status: "idle", data: null });
|
|
912
|
-
}
|
|
913
|
-
};
|
|
914
|
-
}
|
|
915
|
-
const location = channel("location", { latitude: 0, longitude: 0, accuracy: 100, altitude: null, altitudeAccuracy: null, heading: null, speed: null, timestamp: 0, ...options.location });
|
|
916
|
-
const motion = channel("motion", { acceleration: { x: 0, y: 0, z: 0 }, accelerationIncludingGravity: { x: 0, y: 0, z: 9.8 }, rotationRate: { alpha: 0, beta: 0, gamma: 0 }, interval: 16, timestamp: 0, ...options.motion });
|
|
917
|
-
const orientation = channel("orientation", { alpha: 0, beta: 0, gamma: 0, absolute: false, timestamp: 0, ...options.orientation });
|
|
918
|
-
return { version: DEVICE_SENSORS_VERSION, mode: "mock", location, motion, orientation, dispose() {
|
|
919
|
-
location.stop();
|
|
920
|
-
motion.stop();
|
|
921
|
-
orientation.stop();
|
|
922
|
-
} };
|
|
923
|
-
}
|
|
924
|
-
function scopeDeviceSensors(sensors, capabilities = []) {
|
|
925
|
-
const declared = new Set(capabilities);
|
|
926
|
-
const location = declared.has("location") ? sensors.location : inactiveSensor("not-declared", sensors.mode);
|
|
927
|
-
const motion = declared.has("motion") ? sensors.motion : inactiveSensor("not-declared", sensors.mode);
|
|
928
|
-
const orientation = declared.has("orientation") ? sensors.orientation : inactiveSensor("not-declared", sensors.mode);
|
|
929
|
-
return { version: DEVICE_SENSORS_VERSION, mode: sensors.mode, location, motion, orientation, dispose() {
|
|
930
|
-
location.stop();
|
|
931
|
-
motion.stop();
|
|
932
|
-
orientation.stop();
|
|
933
|
-
} };
|
|
934
|
-
}
|
|
935
|
-
function unavailableDeviceSensors() {
|
|
936
|
-
const location = inactiveSensor("unsupported", "real");
|
|
937
|
-
const motion = inactiveSensor("unsupported", "real");
|
|
938
|
-
const orientation = inactiveSensor("unsupported", "real");
|
|
939
|
-
return { version: DEVICE_SENSORS_VERSION, mode: "real", location, motion, orientation, dispose() {
|
|
940
|
-
} };
|
|
941
|
-
}
|
|
942
|
-
|
|
943
661
|
// src/sdk/runtimeContext.ts
|
|
944
662
|
var zeroAddress = "0x0000000000000000000000000000000000000000";
|
|
945
663
|
function explorerForChain(chainId) {
|
|
@@ -996,6 +714,6 @@ function createVaultRuntimeContext(input) {
|
|
|
996
714
|
};
|
|
997
715
|
}
|
|
998
716
|
|
|
999
|
-
export {
|
|
1000
|
-
//# sourceMappingURL=chunk-
|
|
1001
|
-
//# sourceMappingURL=chunk-
|
|
717
|
+
export { FLAP_WALLET_RUNTIME_VERSION, PRESALE_APPROVAL_VERSION, chainLabelForChain, createFlapChainSdk, createIpfsTextReader, createVaultRuntimeContext, explorerForChain, parseAppWalletContracts, readContractEventsInBlockRanges, readFsiJson, resolveSafeContractWriteFeeOverrides };
|
|
718
|
+
//# sourceMappingURL=chunk-SFUJ26PT.js.map
|
|
719
|
+
//# sourceMappingURL=chunk-SFUJ26PT.js.map
|