-
Notifications
You must be signed in to change notification settings - Fork 7
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
cmd
committed
Feb 2, 2024
1 parent
5148931
commit 077cd09
Showing
20 changed files
with
203 additions
and
107 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
Empty file.
Empty file.
Empty file.
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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import { EscrowClient } from '@scrow/core/client' | ||
import { config } from '../../00_demo_config.js' | ||
|
||
const dpid = '798e5e4a51e60dea79690dcd3114f65fa510c539514e8f89d6a22beaed98473a' | ||
|
||
const client = new EscrowClient(config) | ||
|
||
// Request an account for the member to use. | ||
const res = await client.deposit.read(dpid) | ||
import { print_banner } from '@scrow/test' | ||
import { client } from '@scrow/demo/01_create_client.js' | ||
import { locked_deposit } from '@scrow/demo/07_deposit_funds.js' | ||
|
||
// Request to read a deposit via dpid. | ||
const res = await client.deposit.read(locked_deposit.dpid) | ||
// Check the response is valid. | ||
if (!res.ok) throw new Error(res.error) | ||
// Unpack the data response | ||
const deposit = res.data.deposit | ||
|
||
const { deposit } = res.data | ||
|
||
print_banner('locked deposit') | ||
console.dir(deposit, { depth : null }) | ||
console.log('\n') |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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,46 @@ | ||
import { EscrowClient } from '../class/client.js' | ||
|
||
import { | ||
ServerKeysResponse, | ||
ServerPolicyResponse, | ||
ServerStatusResponse | ||
} from '@/types/api/server.js' | ||
|
||
import { | ||
ApiResponse | ||
} from '@/types/index.js' | ||
|
||
function server_keys_api (client : EscrowClient) { | ||
return async () : Promise<ApiResponse<ServerKeysResponse>> => { | ||
// Formulate the request. | ||
const url = `${client.host}/api/server/keys` | ||
// Return a response. | ||
return client.fetcher<ServerKeysResponse>({ url }) | ||
} | ||
} | ||
|
||
function server_policy_api (client : EscrowClient) { | ||
return async () : Promise<ApiResponse<ServerPolicyResponse>> => { | ||
// Formulate the request. | ||
const url = `${client.host}/api/server/policy` | ||
// Return a response. | ||
return client.fetcher<ServerPolicyResponse>({ url }) | ||
} | ||
} | ||
|
||
function server_status_api (client : EscrowClient) { | ||
return async () : Promise<ApiResponse<ServerStatusResponse>> => { | ||
// Formulate the request. | ||
const url = `${client.host}/api/server/status` | ||
// Return a response. | ||
return client.fetcher<ServerStatusResponse>({ url }) | ||
} | ||
} | ||
|
||
export default function (client : EscrowClient) { | ||
return { | ||
keys : server_keys_api(client), | ||
policy : server_policy_api(client), | ||
status : server_status_api(client) | ||
} | ||
} |
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,67 @@ | ||
|
||
import { EscrowSigner } from '@/client/class/signer.js' | ||
import { find_program } from '@/lib/proposal.js' | ||
import { validate_witness } from '@/validators/program.js' | ||
|
||
import { | ||
create_witness, | ||
sign_witness | ||
} from '@/lib/witness.js' | ||
|
||
import { | ||
ContractData, | ||
WitnessData, | ||
WitnessTemplate | ||
} from '@/types/index.js' | ||
|
||
export function can_sign_api (signer : EscrowSigner) { | ||
return ( | ||
contract : ContractData, | ||
template : WitnessTemplate | WitnessData | ||
) => { | ||
const { action, path, method } = template | ||
const terms = contract.terms | ||
|
||
if (!signer.membership.exists(terms)) { | ||
return false | ||
} | ||
|
||
const cred = signer.membership.claim(terms) | ||
const query = { action, path, method, includes: [ cred.data.pub ] } | ||
const prog = find_program(query, terms.programs) | ||
return prog !== undefined | ||
} | ||
} | ||
|
||
export function sign_witness_api (signer : EscrowSigner) { | ||
return ( | ||
contract : ContractData, | ||
template : WitnessTemplate | ||
) => { | ||
const terms = contract.terms | ||
const cred = signer.membership.claim(terms) | ||
let wdat = create_witness(terms.programs, cred.data.pub, template) | ||
validate_witness(contract, wdat) | ||
return sign_witness(cred.signer, wdat) | ||
} | ||
} | ||
|
||
export function endorse_witness_api (signer : EscrowSigner) { | ||
return ( | ||
contract : ContractData, | ||
witness : WitnessData | ||
) => { | ||
const terms = contract.terms | ||
const cred = signer.membership.claim(terms) | ||
validate_witness(contract, witness) | ||
return sign_witness(cred.signer, witness) | ||
} | ||
} | ||
|
||
export default function (signer : EscrowSigner) { | ||
return { | ||
can_sign : can_sign_api(signer), | ||
endorse : endorse_witness_api(signer), | ||
sign : sign_witness_api(signer), | ||
} | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,27 @@ | ||
|
||
import { EscrowSigner } from '@/client/class/signer.js' | ||
import { find_program } from '@/lib/proposal.js' | ||
import { validate_witness } from '@/validators/program.js' | ||
|
||
import { | ||
create_witness, | ||
sign_witness | ||
} from '@/lib/witness.js' | ||
import { EscrowClient } from '../class/client.js' | ||
|
||
import { | ||
ContractData, | ||
WitnessData, | ||
WitnessTemplate | ||
ApiResponse, | ||
WitnessDataResponse | ||
} from '@/types/index.js' | ||
|
||
export function can_sign_api (signer : EscrowSigner) { | ||
return ( | ||
contract : ContractData, | ||
template : WitnessTemplate | WitnessData | ||
) => { | ||
const { action, path, method } = template | ||
const terms = contract.terms | ||
|
||
if (!signer.membership.exists(terms)) { | ||
return false | ||
} | ||
|
||
const cred = signer.membership.claim(terms) | ||
const query = { action, path, method, includes: [ cred.data.pub ] } | ||
const prog = find_program(query, terms.programs) | ||
return prog !== undefined | ||
} | ||
} | ||
|
||
export function sign_witness_api (signer : EscrowSigner) { | ||
return ( | ||
contract : ContractData, | ||
template : WitnessTemplate | ||
) => { | ||
const terms = contract.terms | ||
const cred = signer.membership.claim(terms) | ||
let wdat = create_witness(terms.programs, cred.data.pub, template) | ||
validate_witness(contract, wdat) | ||
return sign_witness(cred.signer, wdat) | ||
} | ||
} | ||
|
||
export function endorse_witness_api (signer : EscrowSigner) { | ||
return ( | ||
contract : ContractData, | ||
witness : WitnessData | ||
) => { | ||
const terms = contract.terms | ||
const cred = signer.membership.claim(terms) | ||
validate_witness(contract, witness) | ||
return sign_witness(cred.signer, witness) | ||
import * as assert from '@/assert.js' | ||
|
||
function read_witness_api (client : EscrowClient) { | ||
return async ( | ||
wid : string | ||
) : Promise<ApiResponse<WitnessDataResponse>> => { | ||
// Validate witness id. | ||
assert.is_hash(wid) | ||
// Formulate the request. | ||
const url = `${client.host}/api/witness/${wid}` | ||
// Return a response. | ||
return client.fetcher<WitnessDataResponse>({ url }) | ||
} | ||
} | ||
|
||
export default function (signer : EscrowSigner) { | ||
export default function (client : EscrowClient) { | ||
return { | ||
can_sign : can_sign_api(signer), | ||
endorse : endorse_witness_api(signer), | ||
sign : sign_witness_api(signer), | ||
read : read_witness_api(client) | ||
} | ||
} |
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
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,13 @@ | ||
import { ServerConfig } from '../server.js' | ||
|
||
export interface ServerKeysResponse { | ||
pubkeys : string[] | ||
} | ||
|
||
export interface ServerPolicyResponse { | ||
policy : ServerConfig | ||
} | ||
|
||
export interface ServerStatusResponse { | ||
status : string | ||
} |
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,34 @@ | ||
export interface ServerConfig { | ||
contract : { | ||
AGENT_FEE : number | ||
UPDATE_IVAL : number | ||
} | ||
|
||
deposit : { | ||
DEFAULT_LOCKTIME : number | ||
STALE_WINDOW : number | ||
UPDATE_IVAL : number | ||
} | ||
|
||
general : { | ||
STAMP_THOLD : number | ||
} | ||
|
||
proposal : { | ||
ACTION_LIST : string[] | ||
METHOD_LIST : string[] | ||
DEFAULT_NETWORK : string | ||
DEFAULT_DEADLINE : number | ||
DEFAULT_EXPIRES : number | ||
MIN_DEADLINE : number | ||
MAX_EFFECT : number | ||
MIN_EXPIRY : number | ||
MAX_EXPIRY : number | ||
MIN_FEERATE : number | ||
MAX_FEERATE : number | ||
MIN_WINDOW : number | ||
MAX_WINDOW : number | ||
GRACE_PERIOD : number | ||
MAX_MULTISIG : number | ||
} | ||
} |