Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Jan 25, 2024
1 parent 25b6d44 commit 51cabfc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 26 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
contrib
test/data
test/bitcoin.conf
coredata
dist
node_modules
src/**/_*
test/data
test/bitcoin.conf
TODO.md
NOTES.md
*.log
.env*

src/**/_*
15 changes: 6 additions & 9 deletions src/client/api/contract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { verify_endorsement } from '@/lib/member.js'
import { get_proposal_id } from '@/lib/proposal.js'
import { EscrowClient } from '@/client/class/client.js'
import { parse_proposal } from '@/lib/parse.js'
import { verify_proposal } from '@/validators/index.js'

import {
ContractDataResponse,
Expand All @@ -9,11 +11,6 @@ import {
WitnessListResponse
} from '@/client/types.js'

import {
validate_proposal,
verify_proposal
} from '@/validators/index.js'

import {
ApiResponse,
ProposalData,
Expand All @@ -32,13 +29,13 @@ function create_contract_api (
proposal : ProposalData,
signatures ?: string[]
) : Promise<ApiResponse<ContractDataResponse>> => {
// Validate the proposal's format.
validate_proposal(proposal)
// Parse and validate the proposal.
const prop = parse_proposal(proposal)
// Verify the proposal's terms.
verify_proposal(proposal)
verify_proposal(prop)
// Verify any signatures.
if (signatures !== undefined) {
const prop_id = get_proposal_id(proposal)
const prop_id = get_proposal_id(prop)
signatures.forEach(e => verify_endorsement(prop_id, e, true))
}
// Formulate the request url.
Expand Down
13 changes: 5 additions & 8 deletions src/client/api/proposal.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { EscrowSigner } from '@/client/class/signer.js'
import { endorse_proposal } from '@/lib/proposal.js'
import { parse_proposal } from '@/lib/parse.js'
import { verify_proposal } from '@/validators/proposal.js'

import {
add_membership,
rem_membership
} from '@/lib/policy.js'

import {
validate_proposal,
verify_proposal
} from '@/validators/proposal.js'

import { ProposalData, RolePolicy } from '@/types/index.js'

export function is_member_api (signer : EscrowSigner) {
Expand Down Expand Up @@ -40,9 +37,9 @@ export function leave_proposal_api (signer : EscrowSigner) {

export function endorse_proposal_api (client : EscrowSigner) {
return (proposal : ProposalData) => {
validate_proposal(proposal)
verify_proposal(proposal)
return endorse_proposal(proposal, client._signer)
const prop = parse_proposal(proposal)
verify_proposal(prop)
return endorse_proposal(prop, client._signer)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/api/witness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function sign_witness_api (signer : EscrowSigner) {
) => {
const terms = contract.terms
const cred = signer.membership.claim(terms)
let wdat = create_witness(terms.programs, signer.pubkey, template)
let wdat = create_witness(terms.programs, cred.data.pub, template)
validate_witness(contract, wdat)
return sign_witness(cred.signer, wdat)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function add_membership (
if (is_member(mship, proposal)) {
throw new Error('previous role exists for membership')
}

const wallet = new Wallet(xpub)
const pol = Buff.json(role).digest.hex
const rolls = proposal.members.filter(e => e.pol === pol)
Expand Down
6 changes: 3 additions & 3 deletions src/lib/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ export function endorse_proposal (
proposal : ProposalData,
signer : SignerAPI
) : string {
const msg = get_proposal_id(proposal)
const pub = signer.pubkey
const sig = signer.sign(msg)
const msg = get_proposal_id(proposal)
const pub = signer.pubkey
const sig = signer.sign(msg)
return Buff.join([ pub, sig ]).hex
}

0 comments on commit 51cabfc

Please sign in to comment.