-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: push objects on client sync (#81)
- Loading branch information
1 parent
534875b
commit d451fce
Showing
22 changed files
with
1,331 additions
and
146 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
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,17 @@ | ||
#!/usr/bin/env node | ||
|
||
require('esbuild-runner/register'); | ||
|
||
require('../src/bin/create-object/main') | ||
.main(process.argv, { | ||
stdin: process.stdin, | ||
stdout: process.stdout, | ||
stderr: process.stderr, | ||
}) | ||
.then((code) => { | ||
process.exitCode = code; | ||
}) | ||
.catch((err) => { | ||
console.error(err.stack); | ||
process.exit(1); | ||
}); |
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,55 @@ | ||
import { Buffer } from 'buffer'; | ||
import { readFile } from 'fs/promises'; | ||
import { cryptography } from '@votingworks/auth'; | ||
import { v4 } from 'uuid'; | ||
import { Readable } from 'stream'; | ||
import { unsafeParse } from '@votingworks/types'; | ||
import { join } from 'path'; | ||
import { Payload, SignedObject, UuidSchema } from '../../cacvote-server/types'; | ||
import { resolveWorkspace } from '../../workspace'; | ||
|
||
const DEV_CERTS_PATH = join(__dirname, '../../../../../../libs/auth/certs/dev'); | ||
const PRIVATE_KEY_PATH = join(DEV_CERTS_PATH, 'vx-admin-private-key.pem'); | ||
const VX_ADMIN_CERT_AUTHORITY_CERT_PATH = join( | ||
DEV_CERTS_PATH, | ||
'vx-admin-cert-authority-cert.pem' | ||
); | ||
|
||
export async function main(): Promise<void> { | ||
const workspace = await resolveWorkspace(); | ||
|
||
interface TestObject { | ||
name: string; | ||
description: string; | ||
value: number; | ||
} | ||
|
||
const object: TestObject = { | ||
name: 'Test Object', | ||
description: 'This is a test object', | ||
value: 42, | ||
}; | ||
|
||
const payload = new Payload( | ||
'TestObject', | ||
Buffer.from(JSON.stringify(object)) | ||
); | ||
|
||
const certificatesPem = await readFile(VX_ADMIN_CERT_AUTHORITY_CERT_PATH); | ||
const payloadBuffer = Buffer.from(JSON.stringify(payload)); | ||
const signature = await cryptography.signMessage({ | ||
message: Readable.from(payloadBuffer), | ||
signingPrivateKey: { | ||
source: 'file', | ||
path: PRIVATE_KEY_PATH, | ||
}, | ||
}); | ||
const signedObject = new SignedObject( | ||
unsafeParse(UuidSchema, v4()), | ||
payloadBuffer, | ||
certificatesPem, | ||
signature | ||
); | ||
|
||
console.log(await workspace.store.addObject(signedObject)); | ||
} |
Oops, something went wrong.