-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
2,737 additions
and
3,642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": "error" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# armory-sdk | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build armory-sdk` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test armory-sdk` to execute the unit tests via [Jest](https://jestjs.io). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'armory-sdk', | ||
preset: '../../jest.preset.js', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }] | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/packages/armory-sdk' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@narval/armory-sdk", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"axios": "^1.6.7", | ||
"tslib": "^2.3.0", | ||
"uuid": "^9.0.1", | ||
"viem": "^2.7.16", | ||
"zod": "^3.22.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "armory-sdk", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/armory-sdk/src", | ||
"projectType": "library", | ||
"targets": { | ||
"lint": { | ||
"executor": "@nx/eslint:lint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/armory-sdk/**/*.ts"] | ||
} | ||
}, | ||
"test:type": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "make sdk/test/type" | ||
} | ||
}, | ||
"test:unit": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "packages/armory-sdk/jest.unit.ts", | ||
"verbose": true | ||
} | ||
} | ||
}, | ||
"tags": ["package"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lib/evaluate' |
7 changes: 7 additions & 0 deletions
7
packages/armory-sdk/src/lib/__test__/__unit__/api-call.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { armorySdk } from '../../api-call' | ||
|
||
describe('armorySdk', () => { | ||
it('should work', () => { | ||
expect(armorySdk()).toEqual('armory-sdk') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { AccessToken, Decision, Request, addressSchema, hexSchema } from '@narval/policy-engine-shared' | ||
import { jwkSchema } from '@narval/signature' | ||
import { z } from 'zod' | ||
|
||
export const Endpoints = { | ||
engine: { | ||
evaluations: '/evaluations' | ||
}, | ||
vault: { | ||
sign: '/sign', | ||
importPrivateKey: '/import/private-key' | ||
} | ||
} as const | ||
export type Endpoints = (typeof Endpoints)[keyof typeof Endpoints] | ||
|
||
export const ArmoryClientConfigInput = z.object({ | ||
authHost: z.string().optional(), | ||
authSecret: z.string().optional(), | ||
vaultHost: z.string().optional(), | ||
vaultSecret: z.string().optional(), | ||
entityStoreHost: z.string().optional(), | ||
policyStoreHost: z.string().optional(), | ||
authClientId: z.string().optional(), | ||
vaultClientId: z.string().optional(), | ||
signer: jwkSchema | ||
}) | ||
export type ArmoryClientConfigInput = z.infer<typeof ArmoryClientConfigInput> | ||
|
||
export const ArmoryClientConfig = z.object({ | ||
authHost: z.string(), | ||
authSecret: z.string(), | ||
vaultHost: z.string(), | ||
vaultSecret: z.string(), | ||
entityStoreHost: z.string(), | ||
policyStoreHost: z.string(), | ||
authClientId: z.string(), | ||
vaultClientId: z.string(), | ||
signer: jwkSchema | ||
}) | ||
export type ArmoryClientConfig = z.infer<typeof ArmoryClientConfig> | ||
|
||
export const SdkPermitResponse = z.object({ | ||
decision: z.literal(Decision.PERMIT), | ||
accessToken: AccessToken, | ||
request: Request.optional() | ||
}) | ||
export type SdkPermitResponse = z.infer<typeof SdkPermitResponse> | ||
|
||
export const SdkEvaluationResponse = z.discriminatedUnion('decision', [SdkPermitResponse]) | ||
export type SdkEvaluationResponse = z.infer<typeof SdkEvaluationResponse> | ||
|
||
export const ImportPrivateKeyRequest = z.object({ | ||
privateKey: hexSchema, | ||
walletId: z.string().optional() | ||
}) | ||
export type ImportPrivateKeyRequest = z.infer<typeof ImportPrivateKeyRequest> | ||
|
||
export const ImportPrivateKeyResponse = z.object({ | ||
walletId: z.string(), | ||
address: addressSchema | ||
}) | ||
export type ImportPrivateKeyResponse = z.infer<typeof ImportPrivateKeyResponse> | ||
|
||
export const SignatureRequest = z.object({ | ||
request: Request, | ||
accessToken: AccessToken | ||
}) | ||
export type SignatureRequest = z.infer<typeof SignatureRequest> | ||
|
||
export const SignatureResponse = z.object({ | ||
signature: hexSchema | ||
}) | ||
export type SignatureResponse = z.infer<typeof SignatureResponse> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export class NarvalSdkException extends Error { | ||
context: Record<string, unknown> | ||
constructor(message: string, context: Record<string, unknown> = {}) { | ||
super(message) | ||
this.name = 'NarvalSdkException' | ||
this.context = context | ||
} | ||
} | ||
|
||
export class ConfigurationException extends NarvalSdkException { | ||
constructor(message: string, context: Record<string, unknown> = {}) { | ||
super(message, context) | ||
this.name = 'ConfigurationException' | ||
} | ||
} | ||
|
||
export class ForbiddenException extends NarvalSdkException { | ||
code: number | ||
|
||
constructor(message: string, context: Record<string, unknown> = {}, suggestedHttpCode: number = 403) { | ||
super(message, context) | ||
this.code = suggestedHttpCode | ||
this.name = 'ForbiddenException' | ||
} | ||
} | ||
|
||
export class NotImplementedException extends NarvalSdkException { | ||
code: number | ||
|
||
constructor(message: string, context: Record<string, unknown> = {}, suggestedHttpCode: number = 501) { | ||
super(message, context) | ||
this.code = suggestedHttpCode | ||
this.name = 'NotImplementedError' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { | ||
EvaluationResponse, | ||
SerializedEvaluationRequest, | ||
SerializedEvaluationResponse | ||
} from '@narval/policy-engine-shared' | ||
import axios from 'axios' | ||
import { SendEvaluationRequest } from './schema' | ||
|
||
export const sendEvaluationRequest = async (input: SendEvaluationRequest): Promise<EvaluationResponse> => { | ||
const { uri, request, headers } = input | ||
|
||
const serializedRequest = SerializedEvaluationRequest.parse(request) | ||
const { data } = await axios.post<SerializedEvaluationResponse>(uri, serializedRequest, { | ||
headers | ||
}) | ||
|
||
return EvaluationResponse.parse(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { EvaluationRequest, Request } from '@narval/policy-engine-shared' | ||
import { z } from 'zod' | ||
import { ImportPrivateKeyRequest } from '../domain' | ||
|
||
export const BasicHeaders = z.object({ | ||
'x-client-id': z.string(), | ||
'x-client-secret': z.string() | ||
}) | ||
export type BasicHeaders = z.infer<typeof BasicHeaders> | ||
|
||
export const SignatureRequestHeaders = z.object({ | ||
'x-client-id': z.string(), | ||
'detached-jws': z.string(), | ||
authorization: z.string().startsWith('GNAP ') | ||
}) | ||
export type SignatureRequestHeaders = z.infer<typeof SignatureRequestHeaders> | ||
|
||
export const SendSignatureRequest = z.object({ | ||
uri: z.string(), | ||
headers: SignatureRequestHeaders, | ||
request: Request | ||
}) | ||
export type SendSignatureRequest = z.infer<typeof SendSignatureRequest> | ||
|
||
export const SendImportPrivateKey = z.object({ | ||
request: ImportPrivateKeyRequest, | ||
uri: z.string(), | ||
headers: BasicHeaders | ||
}) | ||
export type SendImportPrivateKey = z.infer<typeof SendImportPrivateKey> | ||
|
||
export const SendEvaluationRequest = z.object({ | ||
request: EvaluationRequest, | ||
uri: z.string(), | ||
headers: BasicHeaders | ||
}) | ||
export type SendEvaluationRequest = z.infer<typeof SendEvaluationRequest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { SerializedRequest } from '@narval/policy-engine-shared' | ||
import axios from 'axios' | ||
import { ImportPrivateKeyResponse, SignatureResponse } from '../domain' | ||
import { SendImportPrivateKey, SendSignatureRequest } from './schema' | ||
|
||
export const sendSignatureRequest = async (input: SendSignatureRequest): Promise<SignatureResponse> => { | ||
const { uri, headers, request } = input | ||
const serializedRequest = SerializedRequest.parse(request) | ||
const { data } = await axios.post( | ||
uri, | ||
{ request: serializedRequest }, | ||
{ | ||
headers | ||
} | ||
) | ||
|
||
return data.signature | ||
} | ||
|
||
export const sendImportPrivateKey = async (input: SendImportPrivateKey): Promise<ImportPrivateKeyResponse> => { | ||
const { uri, headers, request } = input | ||
|
||
const { data } = await axios.post(uri, request, { | ||
headers | ||
}) | ||
return data | ||
} |
Oops, something went wrong.