@tnid/core 0.0.1 → 0.0.2

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 CHANGED
@@ -21,6 +21,17 @@ bun add @tnid/core
21
21
  deno add npm:@tnid/core
22
22
  ```
23
23
 
24
+ ## Platform Support
25
+
26
+ | Platform | Minimum Version |
27
+ | -------- | --------------- |
28
+ | Node.js | 20+ |
29
+ | Deno | 1.0+ |
30
+ | Bun | 1.0+ |
31
+ | Browsers | ES2020+ |
32
+
33
+ Requires `globalThis.crypto` (Web Crypto API).
34
+
24
35
  ## Quick Start
25
36
 
26
37
  ```typescript
@@ -1,5 +1,2 @@
1
- export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
2
- export declare const dntGlobalThis: Omit<typeof globalThis, "crypto"> & {
3
- crypto: import("@deno/shim-crypto").Crypto;
4
- };
1
+ export declare const dntGlobalThis: Omit<typeof globalThis, never>;
5
2
  //# sourceMappingURL=_dnt.shims.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,kBAAkB,EAAE,KAAK,SAAS,EAAE,KAAK,qBAAqB,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKrvB,eAAO,MAAM,aAAa;;CAA2C,CAAC"}
1
+ {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
package/esm/_dnt.shims.js CHANGED
@@ -1,8 +1,4 @@
1
- import { crypto } from "@deno/shim-crypto";
2
- export { crypto } from "@deno/shim-crypto";
3
- const dntGlobals = {
4
- crypto,
5
- };
1
+ const dntGlobals = {};
6
2
  export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
7
3
  function createMergeProxy(baseObj, extObj) {
8
4
  return new Proxy(baseObj, {
package/esm/bits.js CHANGED
@@ -2,8 +2,8 @@
2
2
  // Bit Manipulation and TNID Generation
3
3
  // Mask-based approach matching Rust implementation
4
4
  // =============================================================================
5
+ import { crypto } from "./crypto.js";
5
6
  // Masks for UUID version 8 and variant bits
6
- import * as dntShim from "./_dnt.shims.js";
7
7
  export const UUID_V8_MASK = 0x00000000000080008000000000000000n;
8
8
  // V1: 100 random bits scattered across the UUID
9
9
  export const V1_RANDOM_MASK = 0x00000fffffff0fff0fffffffffffffffn;
@@ -62,7 +62,7 @@ export function generateV0(nameBits, timestampMs, randomBits) {
62
62
  random = randomBits;
63
63
  }
64
64
  else {
65
- const randomBytes = dntShim.crypto.getRandomValues(new Uint8Array(8));
65
+ const randomBytes = crypto.getRandomValues(new Uint8Array(8));
66
66
  random = 0n;
67
67
  for (const byte of randomBytes) {
68
68
  random = (random << 8n) | BigInt(byte);
@@ -79,7 +79,7 @@ export function generateV1(nameBits, randomBits) {
79
79
  random = randomBits;
80
80
  }
81
81
  else {
82
- const randomBytes = dntShim.crypto.getRandomValues(new Uint8Array(16));
82
+ const randomBytes = crypto.getRandomValues(new Uint8Array(16));
83
83
  random = 0n;
84
84
  for (const byte of randomBytes) {
85
85
  random = (random << 8n) | BigInt(byte);
@@ -0,0 +1,4 @@
1
+ export declare const crypto: {
2
+ getRandomValues<T extends ArrayBufferView>(array: T): T;
3
+ };
4
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,MAAM,EAA4C;IAC7D,eAAe,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;CACzD,CAAC"}
package/esm/crypto.js ADDED
@@ -0,0 +1,8 @@
1
+ // Web Crypto API accessor
2
+ // Isolates the type assertion to one place. Works in:
3
+ // - Browsers (globalThis.crypto)
4
+ // - Deno (globalThis.crypto)
5
+ // - Node.js 20+ (globalThis.crypto)
6
+ // deno-lint-ignore no-explicit-any
7
+ import * as dntShim from "./_dnt.shims.js";
8
+ export const crypto = dntShim.dntGlobalThis.crypto;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tnid/core",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Type-safe, named, unique identifiers (TNIDs) - UUID-compatible IDs with embedded type names",
5
5
  "keywords": [
6
6
  "uuid",
@@ -30,8 +30,8 @@
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
- "dependencies": {
34
- "@deno/shim-crypto": "~0.3.1"
33
+ "engines": {
34
+ "node": ">=20"
35
35
  },
36
36
  "_generatedBy": "dnt@dev"
37
37
  }
@@ -1,5 +1,2 @@
1
- export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
2
- export declare const dntGlobalThis: Omit<typeof globalThis, "crypto"> & {
3
- crypto: import("@deno/shim-crypto").Crypto;
4
- };
1
+ export declare const dntGlobalThis: Omit<typeof globalThis, never>;
5
2
  //# sourceMappingURL=_dnt.shims.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,kBAAkB,EAAE,KAAK,SAAS,EAAE,KAAK,qBAAqB,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKrvB,eAAO,MAAM,aAAa;;CAA2C,CAAC"}
1
+ {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
@@ -1,12 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dntGlobalThis = exports.crypto = void 0;
4
- const shim_crypto_1 = require("@deno/shim-crypto");
5
- var shim_crypto_2 = require("@deno/shim-crypto");
6
- Object.defineProperty(exports, "crypto", { enumerable: true, get: function () { return shim_crypto_2.crypto; } });
7
- const dntGlobals = {
8
- crypto: shim_crypto_1.crypto,
9
- };
3
+ exports.dntGlobalThis = void 0;
4
+ const dntGlobals = {};
10
5
  exports.dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
11
6
  function createMergeProxy(baseObj, extObj) {
12
7
  return new Proxy(baseObj, {
package/script/bits.js CHANGED
@@ -3,39 +3,6 @@
3
3
  // Bit Manipulation and TNID Generation
4
4
  // Mask-based approach matching Rust implementation
5
5
  // =============================================================================
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || (function () {
23
- var ownKeys = function(o) {
24
- ownKeys = Object.getOwnPropertyNames || function (o) {
25
- var ar = [];
26
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
- return ar;
28
- };
29
- return ownKeys(o);
30
- };
31
- return function (mod) {
32
- if (mod && mod.__esModule) return mod;
33
- var result = {};
34
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
- __setModuleDefault(result, mod);
36
- return result;
37
- };
38
- })();
39
6
  Object.defineProperty(exports, "__esModule", { value: true });
40
7
  exports.V0_RANDOM_MASK = exports.V1_RANDOM_MASK = exports.UUID_V8_MASK = void 0;
41
8
  exports.nameMask = nameMask;
@@ -45,8 +12,8 @@ exports.buildTnidValue = buildTnidValue;
45
12
  exports.valueToBytes = valueToBytes;
46
13
  exports.generateV0 = generateV0;
47
14
  exports.generateV1 = generateV1;
15
+ const crypto_js_1 = require("./crypto.js");
48
16
  // Masks for UUID version 8 and variant bits
49
- const dntShim = __importStar(require("./_dnt.shims.js"));
50
17
  exports.UUID_V8_MASK = 0x00000000000080008000000000000000n;
51
18
  // V1: 100 random bits scattered across the UUID
52
19
  exports.V1_RANDOM_MASK = 0x00000fffffff0fff0fffffffffffffffn;
@@ -105,7 +72,7 @@ function generateV0(nameBits, timestampMs, randomBits) {
105
72
  random = randomBits;
106
73
  }
107
74
  else {
108
- const randomBytes = dntShim.crypto.getRandomValues(new Uint8Array(8));
75
+ const randomBytes = crypto_js_1.crypto.getRandomValues(new Uint8Array(8));
109
76
  random = 0n;
110
77
  for (const byte of randomBytes) {
111
78
  random = (random << 8n) | BigInt(byte);
@@ -122,7 +89,7 @@ function generateV1(nameBits, randomBits) {
122
89
  random = randomBits;
123
90
  }
124
91
  else {
125
- const randomBytes = dntShim.crypto.getRandomValues(new Uint8Array(16));
92
+ const randomBytes = crypto_js_1.crypto.getRandomValues(new Uint8Array(16));
126
93
  random = 0n;
127
94
  for (const byte of randomBytes) {
128
95
  random = (random << 8n) | BigInt(byte);
@@ -0,0 +1,4 @@
1
+ export declare const crypto: {
2
+ getRandomValues<T extends ArrayBufferView>(array: T): T;
3
+ };
4
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,MAAM,EAA4C;IAC7D,eAAe,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;CACzD,CAAC"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ // Web Crypto API accessor
3
+ // Isolates the type assertion to one place. Works in:
4
+ // - Browsers (globalThis.crypto)
5
+ // - Deno (globalThis.crypto)
6
+ // - Node.js 20+ (globalThis.crypto)
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.crypto = void 0;
42
+ // deno-lint-ignore no-explicit-any
43
+ const dntShim = __importStar(require("./_dnt.shims.js"));
44
+ exports.crypto = dntShim.dntGlobalThis.crypto;