@kokuin/token 0.1.0 → 0.1.1
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/lib/identity.js +5 -4
- package/lib/token.js +5 -4
- package/package.json +8 -5
package/lib/identity.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { createTracer, KokuinAttributeKeys, KokuinSpanNames } from '@kokuin/otel';
|
|
1
2
|
import { ed25519, x25519 } from '@noble/curves/ed25519.js';
|
|
2
3
|
import { b64uFromJSON, fromUTF, toB64U } from '@sozai/codec';
|
|
3
|
-
import {
|
|
4
|
+
import { withSpan } from '@sozai/otel';
|
|
4
5
|
import { CODECS, getDID, normalizeDID } from './did.js';
|
|
5
6
|
import { decryptToken } from './jwe.js';
|
|
6
7
|
import { encodeMultibase } from './multibase.js';
|
|
@@ -25,10 +26,10 @@ export function isOwnIdentity(identity) {
|
|
|
25
26
|
const publicKey = ed25519.getPublicKey(privateKey);
|
|
26
27
|
const id = getDID(CODECS.EdDSA, publicKey);
|
|
27
28
|
async function signToken(payload, options = {}) {
|
|
28
|
-
return withSpan(tracer,
|
|
29
|
+
return withSpan(tracer, KokuinSpanNames.TOKEN_SIGN, {
|
|
29
30
|
attributes: {
|
|
30
|
-
[
|
|
31
|
-
[
|
|
31
|
+
[KokuinAttributeKeys.AUTH_DID]: id,
|
|
32
|
+
[KokuinAttributeKeys.AUTH_ALGORITHM]: 'EdDSA'
|
|
32
33
|
}
|
|
33
34
|
}, async ()=>{
|
|
34
35
|
if (payload.iss != null && payload.iss !== id) {
|
package/lib/token.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { createTracer, KokuinAttributeKeys, KokuinSpanNames } from '@kokuin/otel';
|
|
1
2
|
import { b64uFromJSON, b64uToJSON, canonicalStringify, fromB64U, fromUTF } from '@sozai/codec';
|
|
2
|
-
import {
|
|
3
|
+
import { withSpan } from '@sozai/otel';
|
|
3
4
|
import { assertType, isType } from '@sozai/schema';
|
|
4
5
|
import { resolveIssuerWithDoc } from './did.js';
|
|
5
6
|
import { validateAlgorithm, validateSignedHeader, validateSignedPayload, validateUnsignedHeader } from './schemas.js';
|
|
@@ -170,11 +171,11 @@ async function verifyTokenInner(token, options = {}) {
|
|
|
170
171
|
* Verify a token is either unsigned or signed with a valid signature.
|
|
171
172
|
* Also validates time-based claims (exp, nbf) if present.
|
|
172
173
|
*/ export async function verifyToken(token, options = {}) {
|
|
173
|
-
return withSpan(tokenTracer,
|
|
174
|
+
return withSpan(tokenTracer, KokuinSpanNames.TOKEN_VERIFY, {}, async (span)=>{
|
|
174
175
|
const result = await verifyTokenInner(token, options);
|
|
175
176
|
if (isSignedToken(result)) {
|
|
176
|
-
span.setAttribute(
|
|
177
|
-
span.setAttribute(
|
|
177
|
+
span.setAttribute(KokuinAttributeKeys.AUTH_DID, result.payload.iss);
|
|
178
|
+
span.setAttribute(KokuinAttributeKeys.AUTH_ALGORITHM, result.header.alg);
|
|
178
179
|
}
|
|
179
180
|
return result;
|
|
180
181
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kokuin/token",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "JWT signing and verification",
|
|
6
6
|
"keywords": [
|
|
@@ -26,15 +26,18 @@
|
|
|
26
26
|
],
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@sozai/codec": "^0.1.0",
|
|
30
|
-
"@sozai/schema": "^0.1.0",
|
|
31
|
-
"@sozai/otel": "^0.1.0",
|
|
32
29
|
"@noble/ciphers": "^2.1.1",
|
|
33
30
|
"@noble/curves": "^2.0.1",
|
|
34
31
|
"@noble/hashes": "^2.0.0",
|
|
35
|
-
"@scure/base": "^2.2.0"
|
|
32
|
+
"@scure/base": "^2.2.0",
|
|
33
|
+
"@sozai/codec": "^0.1.0",
|
|
34
|
+
"@sozai/otel": "^0.2.0",
|
|
35
|
+
"@sozai/schema": "^0.1.0",
|
|
36
|
+
"@kokuin/otel": "^0.1.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
39
|
+
"@opentelemetry/sdk-trace-base": "^2.8.0",
|
|
40
|
+
"@opentelemetry/sdk-trace-node": "^2.8.0",
|
|
38
41
|
"uint8arrays": "^6.1.1"
|
|
39
42
|
},
|
|
40
43
|
"scripts": {
|