Skip to content
Open
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
2 changes: 1 addition & 1 deletion scripts/generate-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const content = ast.filter((s) => {
return false;
});

const header = `// AUTO-GENERATED: Only components retained from OpenAPI schema\n\n`;
const header = `// AUTO-GENERATED: Only components and enums retained from OpenAPI schema\n\n`;
await writeFile(outputFile, `${header}${astToString(content)}`);

console.log(`🚀 ${specUrl} → ${outputFile}`);
4 changes: 2 additions & 2 deletions src/keri/app/aiding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { components } from '../../types/keria-api-schema.ts';
/** Arguments required to create an identfier */
export interface CreateIdentiferArgs {
transferable?: boolean;
isith?: string | number | string[];
nsith?: string | number | string[];
isith?: string | number | string[] | string[][];
nsith?: string | number | string[] | string[][];
wits?: string[];
toad?: number;
proxy?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/keri/app/contacting.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignifyClient } from './clienting.ts';
import { Operation } from './coring.ts';
import { components } from '../../types/keria-api-schema.ts';
import { ChallengeOperation } from '../core/keyState.ts';

export type Contact = components['schemas']['Contact'];

Expand Down Expand Up @@ -168,7 +168,7 @@ export class Challenges {
* @param words List of challenge words to check for
* @returns A promise to the long running operation
*/
async verify(source: string, words: string[]): Promise<Operation<unknown>> {
async verify(source: string, words: string[]): Promise<ChallengeOperation> {
const path = `/challenges_verify/${source}`;
const method = 'POST';
const data = {
Expand Down
94 changes: 62 additions & 32 deletions src/keri/app/coring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,27 @@ import libsodium from 'libsodium-wrappers-sumo';
import { Salter } from '../core/salter.ts';
import { Matter, MtrDex } from '../core/matter.ts';
import { components } from '../../types/keria-api-schema.ts';
import {
OOBIOperation,
QueryOperation,
EndRoleOperation,
WitnessOperation,
DelegationOperation,
RegistryOperation,
LocSchemeOperation,
ChallengeOperation,
ExchangeOperation,
SubmitOperation,
DoneOperation,
CredentialOperation,
GroupOperation,
DelegatorOperation,
} from '../core/keyState.ts';

type OOBI = components['schemas']['OOBI'];
type KeyState = components['schemas']['KeyStateRecord'];
type KeyEventRecord = components['schemas']['KeyEventRecord'];
type AgentConfig = components['schemas']['AgentConfig'];

export function randomPasscode(): string {
const raw = libsodium.randombytes_buf(16);
Expand Down Expand Up @@ -34,7 +53,7 @@ export class Oobis {
* Get the OOBI(s) for a managed indentifier for a given role
* @param {string} name Name or alias of the identifier
* @param {string} role Authorized role
* @returns {Promise<any>} A promise to the OOBI(s)
* @returns {Promise<OOBI>} A promise to the OOBI(s)
*/
async get(name: string, role: string = 'agent'): Promise<OOBI> {
const path = `/identifiers/${name}/oobis?role=${role}`;
Expand All @@ -48,9 +67,9 @@ export class Oobis {
* @async
* @param {string} oobi The OOBI to be resolver
* @param {string} [alias] Optional name or alias to link the OOBI resolution to a contact
* @returns {Promise<any>} A promise to the long-running operation
* @returns {Promise<OOBIOperation>} A promise to the long-running operation
*/
async resolve(oobi: string, alias?: string): Promise<any> {
async resolve(oobi: string, alias?: string): Promise<OOBIOperation> {
const path = `/oobis`;
const data: any = {
url: oobi,
Expand All @@ -64,17 +83,21 @@ export class Oobis {
}
}

// TODO: the generic will be replaced by specific overrides like IpexOperation
export type Operation<T = unknown> = Omit<
components['schemas']['Operation'],
'response' | 'metadata'
> & {
response?: T;
metadata?: {
depends?: Operation;
[property: string]: any;
};
};
export type Operation =
| OOBIOperation
| QueryOperation
| EndRoleOperation
| WitnessOperation
| DelegationOperation
| RegistryOperation
| LocSchemeOperation
| ChallengeOperation
| ExchangeOperation
| SubmitOperation
| DoneOperation
| CredentialOperation
| GroupOperation
| DelegatorOperation;

export interface OperationsDeps {
fetch(
Expand All @@ -85,10 +108,6 @@ export interface OperationsDeps {
): Promise<Response>;
}

export interface AgentConfig {
iurls?: string[];
}

/**
* Operations
* @remarks
Expand All @@ -110,7 +129,7 @@ export class Operations {
* @param {string} name Name of the operation
* @returns {Promise<Operation>} A promise to the status of the operation
*/
async get<T = unknown>(name: string): Promise<Operation<T>> {
async get(name: string): Promise<Operation> {
const path = `/operations/${name}`;
const data = null;
const method = 'GET';
Expand All @@ -123,7 +142,7 @@ export class Operations {
* @param {string} type Select operations by type
* @returns {Promise<Operation[]>} A list of operations
*/
async list(type?: string): Promise<Operation<any>[]> {
async list(type?: string): Promise<Operation[]> {
const params = new URLSearchParams();
if (type !== undefined) {
params.append('type', type);
Expand All @@ -149,21 +168,28 @@ export class Operations {
/**
* Poll for operation to become completed.
*/
async wait<T>(
op: Operation<T>,
async wait(
op: Operation,
options: {
signal?: AbortSignal;
minSleep?: number;
maxSleep?: number;
increaseFactor?: number;
} = {}
): Promise<Operation<T>> {
): Promise<Operation> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is very problematic below. Is there any way to determine if we give a particular operation, we get that one back...?

Maybe we need an overload for each operation. Like wait(op: OOBIOperation, ..): Promise<OOBIOperation>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to avoid making our lives very very hard in applications that use this library where we need many casts and checks everywhere.

const minSleep = options.minSleep ?? 10;
const maxSleep = options.maxSleep ?? 10000;
const increaseFactor = options.increaseFactor ?? 50;

if (op.metadata?.depends?.done === false) {
await this.wait(op.metadata.depends, options);
if (
op.metadata &&
'depends' in op.metadata &&
op.metadata.depends &&
typeof op.metadata.depends === 'object' &&
'done' in op.metadata.depends &&
op.metadata.depends.done === false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some issues below with depends. depends, if provided, is always another operation, so we should not need to cast it or check these. I see some places below where we have depends pointing to KERI events etc

) {
await this.wait(op.metadata.depends as Operation, options);
}

if (op.done === true) {
Expand Down Expand Up @@ -208,9 +234,9 @@ export class KeyEvents {
* Retrieve key events for an identifier
* @async
* @param {string} pre Identifier prefix
* @returns {Promise<any>} A promise to the key events
* @returns {Promise<KeyEventRecord[]>} A promise to the key events
*/
async get(pre: string): Promise<any> {
async get(pre: string): Promise<KeyEventRecord[]> {
const path = `/events?pre=${pre}`;
const data = null;
const method = 'GET';
Expand All @@ -236,9 +262,9 @@ export class KeyStates {
* Retriene the key state for an identifier
* @async
* @param {string} pre Identifier prefix
* @returns {Promise<any>} A promise to the key states
* @returns {Promise<KeyState[]>} A promise to the key states
*/
async get(pre: string): Promise<any> {
async get(pre: string): Promise<KeyState[]> {
const path = `/states?pre=${pre}`;
const data = null;
const method = 'GET';
Expand All @@ -252,7 +278,7 @@ export class KeyStates {
* @param {Array<string>} pres List of identifier prefixes
* @returns {Promise<any>} A promise to the key states
*/
async list(pres: string[]): Promise<any> {
async list(pres: string[]): Promise<KeyState[]> {
const path = `/states?${pres.map((pre) => `pre=${pre}`).join('&')}`;
const data = null;
const method = 'GET';
Expand All @@ -266,9 +292,13 @@ export class KeyStates {
* @param {string} pre Identifier prefix
* @param {number} [sn] Optional sequence number
* @param {any} [anchor] Optional anchor
* @returns {Promise<any>} A promise to the long-running operation
* @returns {Promise<QueryOperation>} A promise to the long-running operation
*/
async query(pre: string, sn?: string, anchor?: any): Promise<any> {
async query(
pre: string,
sn?: string,
anchor?: any
): Promise<QueryOperation> {
const path = `/queries`;
const data: any = {
pre: pre,
Expand Down
25 changes: 16 additions & 9 deletions src/keri/app/credentialing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ import {
serializeACDCAttachment,
serializeIssExnAttachment,
} from '../core/utils.ts';
import { Operation } from './coring.ts';
import { HabState } from '../core/keyState.ts';
import {
ExchangeOperation,
CredentialOperation,
GroupOperation,
DelegationOperation,
WitnessOperation,
DoneOperation,
HabState,
} from '../core/keyState.ts';

import { components } from '../../types/keria-api-schema.ts';

Expand Down Expand Up @@ -95,13 +102,13 @@ export interface IssueCredentialResult {
acdc: Serder;
anc: Serder;
iss: Serder;
op: Operation;
op: CredentialOperation;
}

export interface RevokeCredentialResult {
anc: Serder;
rev: Serder;
op: Operation;
op: GroupOperation | DelegationOperation | WitnessOperation | DoneOperation;
}

export interface IpexApplyArgs {
Expand Down Expand Up @@ -781,7 +788,7 @@ export class Ipex {
exn: Serder,
sigs: string[],
recp: string[]
): Promise<any> {
): Promise<ExchangeOperation> {
const body = {
exn: exn.sad,
sigs,
Expand Down Expand Up @@ -825,7 +832,7 @@ export class Ipex {
sigs: string[],
atc: string,
recp: string[]
): Promise<any> {
): Promise<ExchangeOperation> {
const body = {
exn: exn.sad,
sigs,
Expand Down Expand Up @@ -869,7 +876,7 @@ export class Ipex {
exn: Serder,
sigs: string[],
recp: string[]
): Promise<any> {
): Promise<ExchangeOperation> {
const body = {
exn: exn.sad,
sigs,
Expand Down Expand Up @@ -937,7 +944,7 @@ export class Ipex {
sigs: string[],
atc: string,
recp: string[]
): Promise<any> {
): Promise<ExchangeOperation> {
const body = {
exn: exn.sad,
sigs: sigs,
Expand Down Expand Up @@ -982,7 +989,7 @@ export class Ipex {
sigs: string[],
atc: string,
recp: string[]
): Promise<any> {
): Promise<ExchangeOperation> {
const body = {
exn: exn.sad,
sigs: sigs,
Expand Down
8 changes: 6 additions & 2 deletions src/keri/app/exchanging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { Pather } from '../core/pather.ts';
import { Counter, CtrDex } from '../core/counter.ts';
import { Saider } from '../core/saider.ts';
import { HabState } from '../core/keyState.ts';
import { Exn } from './grouping.ts';
import { components } from '../../types/keria-api-schema.ts';

export type ExchangeResource = components['schemas']['ExchangeResource'];

/**
* Exchanges
Expand Down Expand Up @@ -101,7 +105,7 @@ export class Exchanges {
/**
* Send exn messaget to list of recipients
* @async
* @returns {Promise<any>} A promise to the list of replay messages
* @returns {Promise<Exn>} A promise to the list of replay messages
* @param name
* @param topic
* @param exn
Expand Down Expand Up @@ -137,7 +141,7 @@ export class Exchanges {
* @returns A promise to the exn message
* @param said The said of the exn message
*/
async get(said: string): Promise<any> {
async get(said: string): Promise<ExchangeResource> {
const path = `/exchanges/${said}`;
const method = 'GET';
const res = await this.client.fetch(path, method, null);
Expand Down
17 changes: 11 additions & 6 deletions src/keri/app/grouping.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { SignifyClient } from './clienting.ts';
import { Dict } from '../core/core.ts';
import { GroupOperation } from '../core/keyState.ts';
import { components } from '../../types/keria-api-schema.ts';

export type Exn = components['schemas']['Exn'];
export type ExnMultisig = components['schemas']['ExnMultisig'];

/**
* Groups
Expand All @@ -19,9 +24,9 @@ export class Groups {
* Get group request messages
* @async
* @param {string} [said] SAID of exn message to load
* @returns {Promise<any>} A promise to the list of replay messages
* @returns {Promise<ExnMultisig[]>} A promise to the list of replay messages
*/
async getRequest(said: string): Promise<any> {
async getRequest(said: string): Promise<ExnMultisig[]> {
const path = `/multisig/request/` + said;
const method = 'GET';
const res = await this.client.fetch(path, method, null);
Expand All @@ -35,14 +40,14 @@ export class Groups {
* @param {Dict<any>} [exn] exn message to send to other members
* @param {string[]} [sigs] signature of the participant over the exn
* @param {string} [atc] additional attachments from embedded events in exn
* @returns {Promise<any>} A promise to the list of replay messages
* @returns {Promise<Exn>} A promise to the list of replay messages
*/
async sendRequest(
name: string,
exn: Dict<any>,
sigs: string[],
atc: string
): Promise<any> {
): Promise<Exn> {
const path = `/identifiers/${name}/multisig/request`;
const method = 'POST';
const data = {
Expand All @@ -64,7 +69,7 @@ export class Groups {
* @param {string} [gid] prefix
* @param {string[]} [smids] array of particpants
* @param {string[]} [rmids] array of particpants
* @returns {Promise<any>} A promise to the list of replay messages
* @returns {Promise<GroupOperation>} A promise to the list of replay messages
*/
async join(
name: string,
Expand All @@ -73,7 +78,7 @@ export class Groups {
gid: string,
smids: string[],
rmids: string[]
): Promise<any> {
): Promise<GroupOperation> {
const path = `/identifiers/${name}/multisig/join`;
const method = 'POST';
const data = {
Expand Down
Loading