@ocap/util 1.29.14 → 1.29.16
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/esm/index.d.mts +2 -1
- package/esm/index.mjs +2 -1
- package/esm/scope-match.d.mts +17 -0
- package/esm/scope-match.mjs +24 -0
- package/lib/index.cjs +3 -0
- package/lib/index.d.cts +2 -1
- package/lib/scope-match.cjs +26 -0
- package/lib/scope-match.d.cts +17 -0
- package/package.json +2 -2
package/esm/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BN } from "./bn.mjs";
|
|
2
|
+
import { scopeMatch, scopeMatchAny } from "./scope-match.mjs";
|
|
2
3
|
import rightPad from "lodash/padEnd.js";
|
|
3
4
|
import leftPad from "lodash/padStart.js";
|
|
4
5
|
import { LiteralUnion } from "type-fest";
|
|
@@ -219,4 +220,4 @@ declare function toDid(address: string): string;
|
|
|
219
220
|
declare function isSameDid(a: string, b: string): boolean;
|
|
220
221
|
declare function formatTxType(type: string): Capitalize<string>;
|
|
221
222
|
//#endregion
|
|
222
|
-
export { BN, BytesType, EncodingType, KeyPairType, UUID, bytesToHex, formatTxType, fromBase58, fromBase64, fromTokenToUnit, fromUnitToToken, hexToBytes, hexToNumber, hexToUtf8, isBN, isBase58btc, isBigNumber, isHex, isHexPrefixed, isHexStrict, isSameDid, isUUID, isUint8Array, leftPad, numberToBN, numberToHex, numberToString, rightPad, stripHexPrefix, toAddress, toBN, toBase58, toBase64, toBuffer, toDid, toHex, toUint8Array, utf8ToHex };
|
|
223
|
+
export { BN, BytesType, EncodingType, KeyPairType, UUID, bytesToHex, formatTxType, fromBase58, fromBase64, fromTokenToUnit, fromUnitToToken, hexToBytes, hexToNumber, hexToUtf8, isBN, isBase58btc, isBigNumber, isHex, isHexPrefixed, isHexStrict, isSameDid, isUUID, isUint8Array, leftPad, numberToBN, numberToHex, numberToString, rightPad, scopeMatch, scopeMatchAny, stripHexPrefix, toAddress, toBN, toBase58, toBase64, toBuffer, toDid, toHex, toUint8Array, utf8ToHex };
|
package/esm/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BN } from "./bn.mjs";
|
|
2
|
+
import { scopeMatch, scopeMatchAny } from "./scope-match.mjs";
|
|
2
3
|
import BaseBN from "bn.js";
|
|
3
4
|
import base64 from "base64-url";
|
|
4
5
|
import base58 from "bs58";
|
|
@@ -425,4 +426,4 @@ function formatTxType(type) {
|
|
|
425
426
|
}
|
|
426
427
|
|
|
427
428
|
//#endregion
|
|
428
|
-
export { BN, UUID, bytesToHex, formatTxType, fromBase58, fromBase64, fromTokenToUnit, fromUnitToToken, hexToBytes, hexToNumber, hexToUtf8, isBN, isBase58btc, isBigNumber, isHex, isHexPrefixed, isHexStrict, isSameDid, isUUID, isUint8Array, leftPad, numberToBN, numberToHex, numberToString, rightPad, stripHexPrefix, toAddress, toBN, toBase58, toBase64, toBuffer, toDid, toHex, toUint8Array, utf8ToHex };
|
|
429
|
+
export { BN, UUID, bytesToHex, formatTxType, fromBase58, fromBase64, fromTokenToUnit, fromUnitToToken, hexToBytes, hexToNumber, hexToUtf8, isBN, isBase58btc, isBigNumber, isHex, isHexPrefixed, isHexStrict, isSameDid, isUUID, isUint8Array, leftPad, numberToBN, numberToHex, numberToString, rightPad, scopeMatch, scopeMatchAny, stripHexPrefix, toAddress, toBN, toBase58, toBase64, toBuffer, toDid, toHex, toUint8Array, utf8ToHex };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/scope-match.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check if a scope matches a pattern.
|
|
4
|
+
*
|
|
5
|
+
* Matching rules:
|
|
6
|
+
* - Exact match: 'fg:t:transfer' matches 'fg:t:transfer'
|
|
7
|
+
* - Wildcard: 'fg:t:transfer' matches 'fg:t:*' (pattern ends with ':*')
|
|
8
|
+
* - Prefix with segment boundary: 'fg:x:connect:authPrincipal' matches 'fg:x:connect'
|
|
9
|
+
* but 'fg:x:connectFoo' does NOT match 'fg:x:connect'
|
|
10
|
+
*/
|
|
11
|
+
declare function scopeMatch(scope: string, pattern: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Check if a scope matches any of the given patterns.
|
|
14
|
+
*/
|
|
15
|
+
declare function scopeMatchAny(scope: string, patterns: string[]): boolean;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { scopeMatch, scopeMatchAny };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/scope-match.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check if a scope matches a pattern.
|
|
4
|
+
*
|
|
5
|
+
* Matching rules:
|
|
6
|
+
* - Exact match: 'fg:t:transfer' matches 'fg:t:transfer'
|
|
7
|
+
* - Wildcard: 'fg:t:transfer' matches 'fg:t:*' (pattern ends with ':*')
|
|
8
|
+
* - Prefix with segment boundary: 'fg:x:connect:authPrincipal' matches 'fg:x:connect'
|
|
9
|
+
* but 'fg:x:connectFoo' does NOT match 'fg:x:connect'
|
|
10
|
+
*/
|
|
11
|
+
function scopeMatch(scope, pattern) {
|
|
12
|
+
if (scope === pattern) return true;
|
|
13
|
+
if (pattern.endsWith(":*")) return scope.startsWith(pattern.slice(0, -1));
|
|
14
|
+
return scope.startsWith(`${pattern}:`);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Check if a scope matches any of the given patterns.
|
|
18
|
+
*/
|
|
19
|
+
function scopeMatchAny(scope, patterns) {
|
|
20
|
+
return patterns.some((p) => scopeMatch(scope, p));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { scopeMatch, scopeMatchAny };
|
package/lib/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_bn = require('./bn.cjs');
|
|
3
|
+
const require_scope_match = require('./scope-match.cjs');
|
|
3
4
|
let bn_js = require("bn.js");
|
|
4
5
|
bn_js = require_rolldown_runtime.__toESM(bn_js);
|
|
5
6
|
let base64_url = require("base64-url");
|
|
@@ -464,6 +465,8 @@ exports.numberToBN = numberToBN;
|
|
|
464
465
|
exports.numberToHex = numberToHex;
|
|
465
466
|
exports.numberToString = numberToString;
|
|
466
467
|
exports.rightPad = lodash_padEnd.default;
|
|
468
|
+
exports.scopeMatch = require_scope_match.scopeMatch;
|
|
469
|
+
exports.scopeMatchAny = require_scope_match.scopeMatchAny;
|
|
467
470
|
exports.stripHexPrefix = stripHexPrefix;
|
|
468
471
|
exports.toAddress = toAddress;
|
|
469
472
|
exports.toBN = toBN;
|
package/lib/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BN } from "./bn.cjs";
|
|
2
|
+
import { scopeMatch, scopeMatchAny } from "./scope-match.cjs";
|
|
2
3
|
import rightPad from "lodash/padEnd";
|
|
3
4
|
import leftPad from "lodash/padStart";
|
|
4
5
|
import { LiteralUnion } from "type-fest";
|
|
@@ -219,4 +220,4 @@ declare function toDid(address: string): string;
|
|
|
219
220
|
declare function isSameDid(a: string, b: string): boolean;
|
|
220
221
|
declare function formatTxType(type: string): Capitalize<string>;
|
|
221
222
|
//#endregion
|
|
222
|
-
export { BN, BytesType, EncodingType, KeyPairType, UUID, bytesToHex, formatTxType, fromBase58, fromBase64, fromTokenToUnit, fromUnitToToken, hexToBytes, hexToNumber, hexToUtf8, isBN, isBase58btc, isBigNumber, isHex, isHexPrefixed, isHexStrict, isSameDid, isUUID, isUint8Array, leftPad, numberToBN, numberToHex, numberToString, rightPad, stripHexPrefix, toAddress, toBN, toBase58, toBase64, toBuffer, toDid, toHex, toUint8Array, utf8ToHex };
|
|
223
|
+
export { BN, BytesType, EncodingType, KeyPairType, UUID, bytesToHex, formatTxType, fromBase58, fromBase64, fromTokenToUnit, fromUnitToToken, hexToBytes, hexToNumber, hexToUtf8, isBN, isBase58btc, isBigNumber, isHex, isHexPrefixed, isHexStrict, isSameDid, isUUID, isUint8Array, leftPad, numberToBN, numberToHex, numberToString, rightPad, scopeMatch, scopeMatchAny, stripHexPrefix, toAddress, toBN, toBase58, toBase64, toBuffer, toDid, toHex, toUint8Array, utf8ToHex };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/scope-match.ts
|
|
3
|
+
/**
|
|
4
|
+
* Check if a scope matches a pattern.
|
|
5
|
+
*
|
|
6
|
+
* Matching rules:
|
|
7
|
+
* - Exact match: 'fg:t:transfer' matches 'fg:t:transfer'
|
|
8
|
+
* - Wildcard: 'fg:t:transfer' matches 'fg:t:*' (pattern ends with ':*')
|
|
9
|
+
* - Prefix with segment boundary: 'fg:x:connect:authPrincipal' matches 'fg:x:connect'
|
|
10
|
+
* but 'fg:x:connectFoo' does NOT match 'fg:x:connect'
|
|
11
|
+
*/
|
|
12
|
+
function scopeMatch(scope, pattern) {
|
|
13
|
+
if (scope === pattern) return true;
|
|
14
|
+
if (pattern.endsWith(":*")) return scope.startsWith(pattern.slice(0, -1));
|
|
15
|
+
return scope.startsWith(`${pattern}:`);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check if a scope matches any of the given patterns.
|
|
19
|
+
*/
|
|
20
|
+
function scopeMatchAny(scope, patterns) {
|
|
21
|
+
return patterns.some((p) => scopeMatch(scope, p));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.scopeMatch = scopeMatch;
|
|
26
|
+
exports.scopeMatchAny = scopeMatchAny;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/scope-match.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check if a scope matches a pattern.
|
|
4
|
+
*
|
|
5
|
+
* Matching rules:
|
|
6
|
+
* - Exact match: 'fg:t:transfer' matches 'fg:t:transfer'
|
|
7
|
+
* - Wildcard: 'fg:t:transfer' matches 'fg:t:*' (pattern ends with ':*')
|
|
8
|
+
* - Prefix with segment boundary: 'fg:x:connect:authPrincipal' matches 'fg:x:connect'
|
|
9
|
+
* but 'fg:x:connectFoo' does NOT match 'fg:x:connect'
|
|
10
|
+
*/
|
|
11
|
+
declare function scopeMatch(scope: string, pattern: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Check if a scope matches any of the given patterns.
|
|
14
|
+
*/
|
|
15
|
+
declare function scopeMatchAny(scope: string, patterns: string[]): boolean;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { scopeMatch, scopeMatchAny };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/util",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "utils shared across multiple forge js libs, works in both node.js and browser",
|
|
6
6
|
"keywords": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@ocap/types": "1.29.
|
|
15
|
+
"@ocap/types": "1.29.16",
|
|
16
16
|
"@types/bn.js": "^5.2.0",
|
|
17
17
|
"base64-url": "^2.3.3",
|
|
18
18
|
"bn.js": "5.2.3",
|