-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update friendship cert to [#168]
- Loading branch information
1 parent
e4bbc10
commit 9f15753
Showing
4 changed files
with
69 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { PersonIdentifier } from '../../database/type' | ||
|
||
/** | ||
* Server guide: | ||
* - On receive `packed`: | ||
|
@@ -9,22 +11,22 @@ | |
* @remarks | ||
* ! This object should be encrypted with a NEW RANDOM crypto key ! | ||
*/ | ||
export interface FriendshipCertificateV1 { | ||
export interface FriendshipCertificateDecryptedV1 { | ||
/** | ||
* Indicates which Social Network this certificate belongs to. | ||
* | ||
* @example "[email protected]" | ||
* Who declared they issued this certificate | ||
* ! DO NOT trust this field ! | ||
*/ | ||
network: string | ||
certificateIssuer: PersonIdentifier | ||
/** | ||
* Who claim they signed this certificate. | ||
* @remarks | ||
* ! Do not trust this field ! | ||
* @example "alice.hamilton.2019" | ||
* ? This key is used to join and decrypt the message in the private channel | ||
*/ | ||
myId: string | ||
channelCryptoKey: JsonWebKey | ||
/** | ||
* ? This seed is used to generate the deterministic channel ID | ||
*/ | ||
channelSeed: string | ||
} | ||
export interface FriendshipCertificatePackedV1 { | ||
export interface FriendshipCertificateEncryptedV1 { | ||
version: 1 | ||
/** | ||
* ! A NEW RANDOM crypto key ! | ||
|
@@ -38,10 +40,10 @@ export interface FriendshipCertificatePackedV1 { | |
/** | ||
* timestamp | ||
* ! Server should overwrite it ! | ||
* ? If server is some kind of decentralized instance message service, | ||
* ? use the message timestamp | ||
*/ | ||
timestamp: number | ||
/** | ||
* iv | ||
*/ | ||
/** iv used to decrypt the payload */ | ||
iv: 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 |
---|---|---|
@@ -1,23 +1,7 @@ | ||
import { FriendshipCertificatePackedV1 } from './friendship-cert' | ||
import { FriendshipCertificateEncryptedV1 } from './friendship-cert' | ||
|
||
/** | ||
* Publish new certificate | ||
* POST endpoint/friendship-cert | ||
* Get all certificates after a time | ||
* GET endpoint/friendship-cert?after={timestamp} | ||
*/ | ||
const endpoint = '?' | ||
export async function publishCertificate(cert: FriendshipCertificatePackedV1) { | ||
const response = await fetch(endpoint + '/friendship-cert', { method: 'POST', body: JSON.stringify(cert) }) | ||
return response.ok | ||
} | ||
|
||
export async function pullCertificates(after: number = 0) { | ||
const response = await fetch(endpoint + '/friendship-cert?after=' + after) | ||
const result: FriendshipCertificatePackedV1[] = await response.json() | ||
if (!Array.isArray(result)) { | ||
console.warn('Bad output from server') | ||
return [] | ||
} | ||
return result.filter(x => x.cryptoKey && x.iv && x.payload && x.timestamp && x.version === 1) | ||
} | ||
declare function publishCertificate(cert: FriendshipCertificateEncryptedV1): Promise<void> | ||
declare function pullCertificates( | ||
afterTimeStamp: number, | ||
partition: string, | ||
): Promise<FriendshipCertificateEncryptedV1[]> |
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