Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@
"cryptly",
"flagly",
"gracely",
"isly",
"isoly",
"langly",
"npmrc",
"paramly",
"persistly",
"Renamer",
"selectivly",
"servly",
"servly-azure",
"smoothly",
"tidily",
"transactly",
"uply",
"npmrc"
"uply"
]
}
11 changes: 6 additions & 5 deletions Actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ export class Actor<T extends Actor<T>> {
protected readonly transformers: Property.Transformer[] = []
constructor(readonly id?: string) {}

add(...argument: (Property.Creatable | Property.Transformer | undefined)[]): T {
add(...argument: (Property.Configuration | Property.Transformer | undefined)[]): T {
argument.forEach(
value =>
value && this.transformers.push(Property.Creatable.is(value) ? this.creatableToTransformer(value) : value)
value && this.transformers.push(Property.Configuration.is(value) ? this.creatableToTransformer(value) : value)
)
return this as unknown as T
}

private creatableToTransformer(creatable: Property.Creatable): Property.Transformer {
return Property.Creatable.Converter.is(creatable)
private creatableToTransformer(creatable: Property.Configuration): Property.Transformer {
return Property.Converter.Configuration.is(creatable)
? new Property.Converter(creatable)
: Property.Creatable.Crypto.is(creatable)
: Property.Crypto.Configuration.is(creatable)
? Property.Crypto.create(creatable[0], ...creatable.slice(1))
: new Property.Renamer(creatable)
}
}
export namespace Actor {}
21 changes: 7 additions & 14 deletions Algorithm/Name/Asymmetric.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
export type Asymmetric = "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "PS256" | "PS384" | "PS512"
import { isly } from "isly"

export type Asymmetric = typeof Asymmetric.values[number]

export namespace Asymmetric {
export function is(value: any | Asymmetric): value is Asymmetric {
return (
value == "RS256" ||
value == "RS384" ||
value == "RS512" ||
value == "ES256" ||
value == "ES384" ||
value == "ES512" ||
value == "PS256" ||
value == "PS384" ||
value == "PS512"
)
}
export const values = ["RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512"] as const
export const type = isly.named<Asymmetric>("authly.Algorithm.Name.Asymmetric", isly.string(values))
export const is = type.is
export const flaw = type.flaw
}
10 changes: 6 additions & 4 deletions Algorithm/Name/Symmetric.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export type Symmetric = "HS256" | "HS384" | "HS512"
import { isly } from "isly"

export type Symmetric = typeof Symmetric.values[number]
export namespace Symmetric {
export function is(value: any | Symmetric): value is Symmetric {
return value == "HS256" || value == "HS384" || value == "HS512"
}
export const values = ["HS256", "HS384", "HS512"] as const
export const type = isly.named<Symmetric>("authly.Algorithm.Name.Symmetric", isly.string(values))
export const is = type.is
export const flaw = type.flaw
}
22 changes: 10 additions & 12 deletions Algorithm/Name/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { isly } from "isly"
import { Asymmetric as NameAsymmetric } from "./Asymmetric"
import { Symmetric as NameSymmetric } from "./Symmetric"

export type Name = "none" | NameSymmetric | NameAsymmetric
export type Name = "none" | Name.Symmetric | Name.Asymmetric

export namespace Name {
export function is(value: any | Name): value is Name {
return value == "none" || NameSymmetric.is(value) || NameAsymmetric.is(value)
}
export type Symmetric = NameSymmetric
export namespace Symmetric {
export const is = NameSymmetric.is
}
export type Asymmetric = NameAsymmetric
export namespace Asymmetric {
export const is = NameAsymmetric.is
}
export import Symmetric = NameSymmetric
export import Asymmetric = NameAsymmetric
export const type = isly.named<Name>(
"authly.Algorithm.Name",
isly.union<Name, "none", Symmetric, Asymmetric>(isly.string("none"), Symmetric.type, Asymmetric.type)
)
export const is = type.is
export const flaw = type.flaw
}
6 changes: 3 additions & 3 deletions Algorithm/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { authly } from ".."
import { cryptly } from "cryptly"
import { authly } from "../index"

describe("Algorithm.RS256", () => {
const privateKey =
"MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBANGQ/vA5R46N68mce4AYff1OrGGICum4P9Fs5vbdyDf6/aQQaIjke1N5yK93l1u0a7jVJaRMKcWKzevFArwbX7oDUruJt4B2RFKukz1xkqj6eZ+p2afjtNUFLgbo/QEtS/DqGAqW1f2aoI+ktEa/98MSMJ3ThWko1uOyqDnH7UvDAgMBAAECgYBInbqJGP//mJPMb4mn0FTP0lQPE6ncZLjQY7EAd8cqBrGfCQR/8tP9D+UHUCRFZZYyHMGHVdDfn4JNIR4aek3HsVdCMWKBcfAP4dZ9mgZyQnQHEUyeaV3D5MwpcEaQ60URgNAtBqD+hExBTcwdNHV89jCOsmKsF07mc0Rce8r4kQJBAOsrN6XHQgMAAGeLzLN6XUu2Lc7PcGFulcETbnEFmS/vnFEmDp7QcYmeZR2Nh0oXvcrVNJHNnC5YluvWbAhP2okCQQDkITUhJ5L1nJGn3ysGLKEIPAnBqBDGWbZ46uWGvtAwP1a0838k95blhQF7bDOCmxelbMjDQ4womaxzAaY+9jDrAkBEhPAOzlLOevajNNlsxc9fGvKX2lr9GHJrshSwu5fZnq/l+PezkDo0hcEibjUoAmjbK2nIvaau3kMC7hPGDDY5AkADfAJcvEcBW1/aKY11ra7T+l7Hx3JiJTKlTCkvUrDJW95OKz3w6ZszbEGmifOLdiT5UN0MJnb4k8hPhWHtqkL7AkBhZ27YxBXJNQJQjr6spZhXgP2ayBhaRB+6JKVTfcJQpDQyXIIRlBZS1HQBesn8ZIk69t9n6NJTAhRv0QWILFXe"

it("sign", async () => {
const algorithm = authly.Algorithm.RS256(undefined, privateKey)
const signature = algorithm
? await algorithm.sign(
"amount=2050&currency=EUR&ip=1.1.1.1&card[pan]=4111111111111111&card[expire_month]=06&card[expire_year]=2022&card[csc]=123"
)
: ""
const hexadecimalSignature = authly.Identifier.toHexadecimal(signature)
const hexadecimalSignature = cryptly.Identifier.toHexadecimal(signature)
expect(hexadecimalSignature).toEqual(
"881de666d7f61c796c1c900784901b1b9bb8298af26bf10f79b2fd59231ab3383d9183ea8120bac3abead1000c4fab63bf6cf1345a31209acfe910c9286e9a3db7d4d15d1ae8e279ef05d5e43184b608ad39741ab04e28095fb8a0c48974e55fd0fe58ac5ef1f6c16670f67fd1c1b9a2a06273b079dc29e0daef6319a2e63545"
)
Expand Down
13 changes: 1 addition & 12 deletions Algorithm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,5 @@ export class Algorithm {
}
}
export namespace Algorithm {
export type Name = AlgorithmName
export namespace Name {
export const is = AlgorithmName.is
export type Symmetric = AlgorithmName.Symmetric
export namespace Symmetric {
export const is = AlgorithmName.Symmetric.is
}
export type Asymmetric = AlgorithmName.Asymmetric
export namespace Asymmetric {
export const is = AlgorithmName.Asymmetric.is
}
}
export import Name = AlgorithmName
}
1 change: 1 addition & 0 deletions Issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ export class Issuer<T extends Payload> extends Actor<Issuer<T>> {
return (algorithm && new Issuer(issuer, algorithm)) || undefined
}
}
export namespace Issuer {}
19 changes: 19 additions & 0 deletions Property/Configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { isly } from "isly"
import { Converter } from "./Converter"
import { Crypto } from "./Crypto"
import { Renamer } from "./Renamer"

export type Configuration = Converter.Configuration | Crypto.Configuration | Renamer.Configuration

export namespace Configuration {
export const type = isly.named<Configuration>(
"authly.Property.Configuration",
isly.union<Configuration, Converter.Configuration, Crypto.Configuration, Renamer.Configuration>(
Converter.Configuration.type,
Crypto.Configuration.type,
Renamer.Configuration.type
)
)
export const is = type.is
export const flaw = type.flaw
}
79 changes: 0 additions & 79 deletions Property/Converter.spec.ts

This file was deleted.

35 changes: 0 additions & 35 deletions Property/Converter.ts

This file was deleted.

52 changes: 52 additions & 0 deletions Property/Converter/Configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { isly } from "isly"
import { Payload } from "../../Payload"

type Mapping<TObject> = TObject extends Array<unknown>
? never
: {
[TKey in keyof TObject as string]: TKey extends string | number
? TObject[TKey] extends Array<unknown>
? `${TKey}`
: TObject[TKey] extends Record<any, any>
? DotNotation<TObject[TKey]> extends string | number
? `${TKey}` | `${TKey}.${DotNotation<TObject[TKey]>}`
: never
: `${TKey}`
: never
}
type DotNotation<TObject> = TObject extends string | number ? `${TObject}` : Mapping<TObject>[keyof Mapping<TObject>]

type GetValue<P extends string, Source extends Record<string, any>> = P extends keyof Source
? Source[P]
: P extends `${infer Head}.${infer Tail}`
? GetValue<Tail, Source[Head]>
: Source[P]

type MaybePromise<T> = T | Promise<T> | Partial<number>
export type Configuration<S extends Record<string, unknown> = Record<string, unknown>, T extends Payload = Payload> = {
[P in DotNotation<S>]?: {
encode: (
value: GetValue<P, S>
) => MaybePromise<(P extends DotNotation<T> ? GetValue<P, T> : Payload.Value) | undefined>
decode: (
value: (P extends DotNotation<T> ? GetValue<P, T> : Payload.Value) | undefined
) => MaybePromise<GetValue<P, S>> | undefined
}
}

export namespace Configuration {
export const type = isly.named<Configuration<Record<string, unknown>, Payload>>(
"authly.Property.Converter.Configuration<T>",
isly.record<Configuration>(
isly.string(),
isly
.object<{ encode: (...params: any[]) => any; decode: (...params: any[]) => any }>({
encode: isly.function(),
decode: isly.function(),
})
.optional()
)
)
export const is = type.is
export const flaw = type.flaw
}
Loading
Loading