-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: accept header #253
base: main
Are you sure you want to change the base?
feat: accept header #253
Changes from 15 commits
8635d5a
d9b5ee9
60b1dbd
bf19cb8
e0882d4
ec1dc46
939ffb2
23673b8
8d673ff
3dbf2ca
1f6d6cd
babd7d3
245260e
b982bc6
7d8667b
e775a41
fb82622
0bed0ba
b6d7084
e3161bd
189e973
936acba
fbd0026
684292b
2185278
1c34e2d
dcd9a6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,21 @@ export class PackageManager implements IPackageManager { | |
this.packers = new Map<MediaType, IPacker>(); | ||
} | ||
|
||
/** {@inheritDoc IPackageManager.isSupported} */ | ||
isSupported(mediaType: MediaType, profile: string): boolean { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should rename interface method to |
||
const p = this.packers.get(mediaType); | ||
if (!p) { | ||
return false; | ||
} | ||
|
||
return p.isProfileSupported(profile); | ||
} | ||
|
||
/** {@inheritDoc IPackageManager.getSupportedMediaTypes} */ | ||
getSupportedMediaTypes(): MediaType[] { | ||
return [...this.packers.keys()]; | ||
} | ||
|
||
/** {@inheritDoc IPackageManager.registerPackers} */ | ||
registerPackers(packers: Array<IPacker>): void { | ||
packers.forEach((p) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,10 @@ import { | |
ErrStateVerificationFailed, | ||
ErrUnknownCircuitID | ||
} from '../errors'; | ||
import { MediaType } from '../constants'; | ||
import { AcceptAuthCircuits, AcceptJwzAlgorithms, MediaType } from '../constants'; | ||
import { byteDecoder, byteEncoder } from '../../utils'; | ||
import { DEFAULT_AUTH_VERIFY_DELAY } from '../constants'; | ||
import { parseAcceptProfile } from '../utils'; | ||
|
||
const { getProvingMethod } = proving; | ||
|
||
|
@@ -174,6 +175,49 @@ export class ZKPPacker implements IPacker { | |
mediaType(): MediaType { | ||
return MediaType.ZKPMessage; | ||
} | ||
|
||
/** {@inheritDoc IPacker.getEnvelope} */ | ||
getEnvelope(): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and in future I guess we will have potentially an array of strings even for one media type, maybe we should return an array of strings and rename methods to getSupportedProfiles() |
||
return `env=${this.mediaType()}&alg=${this.getSupportedAlgorithms().join( | ||
',' | ||
)}&circuitIds=${this.getSupportedCircuitIds().join(',')}`; | ||
} | ||
|
||
/** {@inheritDoc IPacker.isProfileSupported} */ | ||
isProfileSupported(profile: string) { | ||
const { env, circuits, alg } = parseAcceptProfile(profile); | ||
if (env !== this.mediaType()) { | ||
return false; | ||
} | ||
|
||
let circuitIdSupported = !circuits?.length; | ||
const supportedCircuitIds = this.getSupportedCircuitIds(); | ||
for (const c of circuits || []) { | ||
if (supportedCircuitIds.includes(c)) { | ||
circuitIdSupported = true; | ||
break; | ||
} | ||
} | ||
|
||
let algSupported = !alg?.length; | ||
const supportedAlgs = this.getSupportedAlgorithms(); | ||
for (const a of alg || []) { | ||
if (supportedAlgs.includes(a as AcceptJwzAlgorithms)) { | ||
algSupported = true; | ||
break; | ||
} | ||
} | ||
|
||
return algSupported && circuitIdSupported; | ||
} | ||
|
||
private getSupportedAlgorithms(): AcceptJwzAlgorithms[] { | ||
return [AcceptJwzAlgorithms.groth16]; | ||
} | ||
|
||
private getSupportedCircuitIds(): AcceptAuthCircuits[] { | ||
return [AcceptAuthCircuits.authV2]; | ||
} | ||
} | ||
|
||
const verifySender = async (token: Token, msg: BasicMessage): Promise<void> => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { | ||
AcceptAuthCircuits, | ||
AcceptJwsAlgorithms, | ||
AcceptJwzAlgorithms, | ||
MediaType, | ||
ProtocolVersion | ||
} from '../../constants'; | ||
|
||
export type AcceptProfile = { | ||
protocolVersion: ProtocolVersion; | ||
env: MediaType; | ||
circuits?: AcceptAuthCircuits[]; | ||
alg?: AcceptJwsAlgorithms[] | AcceptJwzAlgorithms[]; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new Error('no packer with profile which meets
access
header requirements');Comment