@naculus/connect-appkit-core 0.10.0 → 0.11.0
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.cjs +30 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +30 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -867,6 +867,8 @@ interface DescribeAuthorizationOptions {
|
|
|
867
867
|
locale?: string;
|
|
868
868
|
/** Unix timestamp in seconds. */
|
|
869
869
|
now?: number;
|
|
870
|
+
/** Enforcement reported by a successful authorization compile result. */
|
|
871
|
+
enforcement?: "on-chain" | "device";
|
|
870
872
|
}
|
|
871
873
|
interface AuthorizationRecipientView {
|
|
872
874
|
shortened: string;
|
|
@@ -883,6 +885,11 @@ interface AuthorizationGrantView {
|
|
|
883
885
|
perPayment: AuthorizationAmountView;
|
|
884
886
|
total: AuthorizationAmountView;
|
|
885
887
|
count: number | null;
|
|
888
|
+
period: {
|
|
889
|
+
amount: AuthorizationAmountView;
|
|
890
|
+
every: string;
|
|
891
|
+
startsAt: string;
|
|
892
|
+
} | null;
|
|
886
893
|
rails: string[];
|
|
887
894
|
}
|
|
888
895
|
interface AuthorizationExpiryView {
|
|
@@ -895,6 +902,8 @@ interface AuthorizationDescription {
|
|
|
895
902
|
principal: string | null;
|
|
896
903
|
grants: AuthorizationGrantView[];
|
|
897
904
|
expiry: AuthorizationExpiryView;
|
|
905
|
+
enforcement: "on-chain" | "device" | null;
|
|
906
|
+
enforcementLabel: string | null;
|
|
898
907
|
warnings: string[];
|
|
899
908
|
}
|
|
900
909
|
declare function formatAuthorizationAmount(amount: bigint, metadata: AuthorizationAssetMetadata | undefined): AuthorizationAmountView;
|
package/dist/index.d.ts
CHANGED
|
@@ -867,6 +867,8 @@ interface DescribeAuthorizationOptions {
|
|
|
867
867
|
locale?: string;
|
|
868
868
|
/** Unix timestamp in seconds. */
|
|
869
869
|
now?: number;
|
|
870
|
+
/** Enforcement reported by a successful authorization compile result. */
|
|
871
|
+
enforcement?: "on-chain" | "device";
|
|
870
872
|
}
|
|
871
873
|
interface AuthorizationRecipientView {
|
|
872
874
|
shortened: string;
|
|
@@ -883,6 +885,11 @@ interface AuthorizationGrantView {
|
|
|
883
885
|
perPayment: AuthorizationAmountView;
|
|
884
886
|
total: AuthorizationAmountView;
|
|
885
887
|
count: number | null;
|
|
888
|
+
period: {
|
|
889
|
+
amount: AuthorizationAmountView;
|
|
890
|
+
every: string;
|
|
891
|
+
startsAt: string;
|
|
892
|
+
} | null;
|
|
886
893
|
rails: string[];
|
|
887
894
|
}
|
|
888
895
|
interface AuthorizationExpiryView {
|
|
@@ -895,6 +902,8 @@ interface AuthorizationDescription {
|
|
|
895
902
|
principal: string | null;
|
|
896
903
|
grants: AuthorizationGrantView[];
|
|
897
904
|
expiry: AuthorizationExpiryView;
|
|
905
|
+
enforcement: "on-chain" | "device" | null;
|
|
906
|
+
enforcementLabel: string | null;
|
|
898
907
|
warnings: string[];
|
|
899
908
|
}
|
|
900
909
|
declare function formatAuthorizationAmount(amount: bigint, metadata: AuthorizationAssetMetadata | undefined): AuthorizationAmountView;
|
package/dist/index.js
CHANGED
|
@@ -1346,6 +1346,25 @@ function relativeExpiry(expiresAt, now, locale) {
|
|
|
1346
1346
|
}
|
|
1347
1347
|
return new Intl.RelativeTimeFormat(locale).format(value, unit);
|
|
1348
1348
|
}
|
|
1349
|
+
function absoluteUtc(timestamp, locale) {
|
|
1350
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1351
|
+
year: "numeric",
|
|
1352
|
+
month: "short",
|
|
1353
|
+
day: "numeric",
|
|
1354
|
+
hour: "2-digit",
|
|
1355
|
+
minute: "2-digit",
|
|
1356
|
+
hourCycle: "h23",
|
|
1357
|
+
timeZone: "UTC",
|
|
1358
|
+
timeZoneName: "short"
|
|
1359
|
+
}).format(timestamp * 1e3);
|
|
1360
|
+
}
|
|
1361
|
+
function formatPeriodLength(seconds) {
|
|
1362
|
+
const [amount, unit] = seconds % 604800 === 0 ? [seconds / 604800, "week"] : seconds % 86400 === 0 ? [seconds / 86400, "day"] : seconds % 3600 === 0 ? [seconds / 3600, "hour"] : seconds % 60 === 0 ? [seconds / 60, "minute"] : [seconds, "second"];
|
|
1363
|
+
return `${amount} ${unit}${amount === 1 ? "" : "s"}`;
|
|
1364
|
+
}
|
|
1365
|
+
function formatAuthorizationEnforcement(enforcement) {
|
|
1366
|
+
return enforcement === "on-chain" ? "Limits enforced by the blockchain" : enforcement === "device" ? "Limits enforced by this device" : null;
|
|
1367
|
+
}
|
|
1349
1368
|
function describeAuthorization(input, options = {}) {
|
|
1350
1369
|
const now = options.now ?? Math.floor(Date.now() / 1e3);
|
|
1351
1370
|
const locale = options.locale ?? "en";
|
|
@@ -1367,23 +1386,23 @@ function describeAuthorization(input, options = {}) {
|
|
|
1367
1386
|
perPayment: formatAuthorizationAmount(grant.maxPerPayment, metadata),
|
|
1368
1387
|
total: formatAuthorizationAmount(grant.maxTotal, metadata),
|
|
1369
1388
|
count: grant.maxCount ?? null,
|
|
1389
|
+
period: grant.period ? {
|
|
1390
|
+
amount: formatAuthorizationAmount(grant.period.amount, metadata),
|
|
1391
|
+
every: formatPeriodLength(grant.period.seconds),
|
|
1392
|
+
startsAt: absoluteUtc(grant.period.start, locale)
|
|
1393
|
+
} : null,
|
|
1370
1394
|
rails: grant.rails.map((r) => r.replace("-", " "))
|
|
1371
1395
|
};
|
|
1372
1396
|
}),
|
|
1373
1397
|
expiry: {
|
|
1374
1398
|
timestamp: input.expiresAt,
|
|
1375
|
-
absolute:
|
|
1376
|
-
year: "numeric",
|
|
1377
|
-
month: "short",
|
|
1378
|
-
day: "numeric",
|
|
1379
|
-
hour: "2-digit",
|
|
1380
|
-
minute: "2-digit",
|
|
1381
|
-
hourCycle: "h23",
|
|
1382
|
-
timeZone: "UTC",
|
|
1383
|
-
timeZoneName: "short"
|
|
1384
|
-
}).format(input.expiresAt * 1e3),
|
|
1399
|
+
absolute: absoluteUtc(input.expiresAt, locale),
|
|
1385
1400
|
relative: relativeExpiry(input.expiresAt, now, locale)
|
|
1386
1401
|
},
|
|
1402
|
+
enforcement: options.enforcement ?? null,
|
|
1403
|
+
enforcementLabel: formatAuthorizationEnforcement(
|
|
1404
|
+
options.enforcement ?? null
|
|
1405
|
+
),
|
|
1387
1406
|
warnings: flags.map(
|
|
1388
1407
|
(flag) => flag === "unrestricted-recipient-legacy" ? "This key can pay any recipient." : "This key can do more than shown here."
|
|
1389
1408
|
)
|
|
@@ -1397,6 +1416,7 @@ var REFUSAL_SENTENCES = {
|
|
|
1397
1416
|
"over-per-payment": "This amount exceeds the per-payment limit.",
|
|
1398
1417
|
"over-total": "This amount exceeds the remaining total limit.",
|
|
1399
1418
|
"over-count": "This authorization has reached its payment count limit.",
|
|
1419
|
+
"period-limit-exceeded": "This amount exceeds the limit for the current period.",
|
|
1400
1420
|
"rail-not-allowed": "This payment rail is not allowed.",
|
|
1401
1421
|
"invalid-authorization": "The authorization or spend request is invalid."
|
|
1402
1422
|
};
|