Skip to content

Commit

Permalink
Add new announcement types for Attribute Sets (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: Wes Biggs <[email protected]>
  • Loading branch information
wesbiggs and Wes Biggs authored Sep 18, 2024
1 parent 73135c6 commit 7e327e3
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 33 deletions.
42 changes: 34 additions & 8 deletions announcements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import reaction from "./parquet/reaction.js";
import reply from "./parquet/reply.js";
import tombstone from "./parquet/tombstone.js";
import update from "./parquet/update.js";
import userAttributeSet from "./parquet/user-attribute-set.js";
import dsnpContentAttributeSet from "./parquet/dsnp-content-attribute-set.js";
import externalContentAttributeSet from "./parquet/external-content-attribute-set.js";

import { DSNPParquetSchema } from "./types/dsnp-parquet.js";

Expand All @@ -12,6 +15,9 @@ export enum AnnouncementType {
Reply = 3,
Reaction = 4,
Update = 6,
UserAttributeSet = 8,
DSNPContentAttributeSet = 9,
ExternalContentAttributeSet = 10,
}

export type AnnouncementDescriptor = {
Expand All @@ -21,36 +27,56 @@ export type AnnouncementDescriptor = {
};

export function descriptorForAnnouncementType(announcementType: AnnouncementType): AnnouncementDescriptor {
const base = {
announcementType,
tombstoneAllowed: false,
};

switch (announcementType) {
case AnnouncementType.Tombstone:
return {
announcementType: AnnouncementType.Tombstone,
...base,
parquetSchema: tombstone,
tombstoneAllowed: false,
};
case AnnouncementType.Broadcast:
return {
announcementType: AnnouncementType.Broadcast,
...base,
parquetSchema: broadcast,
tombstoneAllowed: true,
};
case AnnouncementType.Reply:
return {
announcementType: AnnouncementType.Reply,
...base,
parquetSchema: reply,
tombstoneAllowed: true,
};
case AnnouncementType.Reaction:
return {
announcementType: AnnouncementType.Reaction,
...base,
parquetSchema: reaction,
tombstoneAllowed: false,
};
case AnnouncementType.Update:
return {
announcementType: AnnouncementType.Update,
...base,
parquetSchema: update,
tombstoneAllowed: false,
};
case AnnouncementType.UserAttributeSet:
return {
...base,
parquetSchema: userAttributeSet,
tombstoneAllowed: true,
};
case AnnouncementType.DSNPContentAttributeSet:
return {
...base,
parquetSchema: dsnpContentAttributeSet,
tombstoneAllowed: true,
};
case AnnouncementType.ExternalContentAttributeSet:
return {
...base,
parquetSchema: externalContentAttributeSet,
tombstoneAllowed: true,
};
}
throw new Error("Invalid enum value");
Expand Down
7 changes: 0 additions & 7 deletions avro/PublicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ const PublicKey: Schema = {
name: "PublicKey",
namespace: "org.dsnp",
fields: [
// When converting from Frequency Data to DSNP Announcement, assume:
// - announcementType = 7
// - fromId = [Associated MSA Id]
// - keyType = 1 for keyAgreement (used for graph encryption/decryption and PRIds), or
// keyType = 2 for assertionMethod (used for credential signatures)
// - keyId = `index` from the Itemized storage
// DID Key Id could be publicKey or could be the index of the array. Not user assigned
{
name: "publicKey",
doc: "Multicodec public key",
Expand Down
17 changes: 17 additions & 0 deletions parquet/dsnp-content-attribute-set.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { testCompression, testParquetSchema } from "../test/parquet.js";
import * as generators from "@dsnp/test-generators";
import dsnpContentAttributeSetSchema from "./dsnp-content-attribute-set.js";

describe("DSNP Content Attribute Set Spec", () => {
testParquetSchema(dsnpContentAttributeSetSchema);

testCompression("dsnpContentAttributeSet", dsnpContentAttributeSetSchema, () => ({
announcementType: 9,
fromId: generators.randInt(10000000),
subject: `dsnp://${generators.randInt(10000000)}/bdyqdua4t4pxgy37mdmjyqv3dejp5betyqsznimpneyujsur23yubzna`,
url: `https://www.imadapp.com/data/vcs/${generators.generateHash()}`,
contentHash: "bciqdnu347gcfmxzbkhgoubiobphm6readngitfywktdtbdocgogop2q",
attributeSetType: `did:dsnp:${generators.randInt(10000000)}$MyAttributeSetType`,
issuer: `did:dsnp:${generators.randInt(10000000)}`,
}));
});
58 changes: 58 additions & 0 deletions parquet/dsnp-content-attribute-set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { DSNPParquetSchema } from "../types/dsnp-parquet.js";

const dsnpContentAttributeSet: DSNPParquetSchema = [
{
name: "announcementType",
column_type: {
INTEGER: {
bit_width: 32,
sign: true,
},
},
compression: "GZIP",
bloom_filter: false,
},
{
name: "fromId",
column_type: {
INTEGER: {
bit_width: 64,
sign: false,
},
},
compression: "GZIP",
bloom_filter: true,
},
{
name: "subject",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
{
name: "url",
column_type: "STRING",
compression: "GZIP",
bloom_filter: false,
},
{
name: "contentHash",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
{
name: "attributeSetType",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
{
name: "issuer",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
];

export default dsnpContentAttributeSet;
18 changes: 18 additions & 0 deletions parquet/external-content-attribute-set.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { testCompression, testParquetSchema } from "../test/parquet.js";
import * as generators from "@dsnp/test-generators";
import externalContentAttributeSetSchema from "./external-content-attribute-set.js";

describe("External Content Attribute Set Spec", () => {
testParquetSchema(externalContentAttributeSetSchema);

testCompression("externalContentAttributeSet", externalContentAttributeSetSchema, () => ({
announcementType: 10,
fromId: generators.randInt(10000000),
subject: "https://www.website.com/somecontent.html",
subjectContentHash: "bciqdnu347gcfmxzbkhgoubiobphm6readngitfywktdtbdocgogop2q",
url: `https://www.imadapp.com/data/vcs/${generators.generateHash()}`,
contentHash: "bciqdnu347gcfmxzbkhgoubiobphm6readngitfywktdtbdocgogop2q",
attributeSetType: `did:dsnp:${generators.randInt(10000000)}$MyAttributeSetType`,
issuer: `did:dsnp:${generators.randInt(10000000)}`,
}));
});
64 changes: 64 additions & 0 deletions parquet/external-content-attribute-set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { DSNPParquetSchema } from "../types/dsnp-parquet.js";

const externalContentAttributeSet: DSNPParquetSchema = [
{
name: "announcementType",
column_type: {
INTEGER: {
bit_width: 32,
sign: true,
},
},
compression: "GZIP",
bloom_filter: false,
},
{
name: "fromId",
column_type: {
INTEGER: {
bit_width: 64,
sign: false,
},
},
compression: "GZIP",
bloom_filter: true,
},
{
name: "subject",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
{
name: "subjectContentHash",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
{
name: "url",
column_type: "STRING",
compression: "GZIP",
bloom_filter: false,
},
{
name: "contentHash",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
{
name: "attributeSetType",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
{
name: "issuer",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
];

export default externalContentAttributeSet;
17 changes: 17 additions & 0 deletions parquet/user-attribute-set.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { testCompression, testParquetSchema } from "../test/parquet.js";
import * as generators from "@dsnp/test-generators";
import userAttributeSetSchema from "./user-attribute-set.js";

describe("User Attribute Set Spec", () => {
testParquetSchema(userAttributeSetSchema);

testCompression("userAttributeSet", userAttributeSetSchema, () => ({
announcementType: 8,
fromId: generators.randInt(10000000),
subject: generators.randInt(10000000),
url: `https://www.imadapp.com/data/vcs/${generators.generateHash()}`,
contentHash: "bciqdnu347gcfmxzbkhgoubiobphm6readngitfywktdtbdocgogop2q",
attributeSetType: `did:dsnp:${generators.randInt(10000000)}$MyAttributeSetType`,
issuer: `did:dsnp:${generators.randInt(10000000)}`,
}));
});
63 changes: 63 additions & 0 deletions parquet/user-attribute-set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { DSNPParquetSchema } from "../types/dsnp-parquet.js";

const userAttributeSet: DSNPParquetSchema = [
{
name: "announcementType",
column_type: {
INTEGER: {
bit_width: 32,
sign: true,
},
},
compression: "GZIP",
bloom_filter: false,
},
{
name: "fromId",
column_type: {
INTEGER: {
bit_width: 64,
sign: false,
},
},
compression: "GZIP",
bloom_filter: true,
},
{
name: "subject",
column_type: {
INTEGER: {
bit_width: 64,
sign: false,
},
},
compression: "GZIP",
bloom_filter: true,
},
{
name: "url",
column_type: "STRING",
compression: "GZIP",
bloom_filter: false,
},
{
name: "contentHash",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
{
name: "attributeSetType",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
{
name: "issuer",
column_type: "STRING",
compression: "GZIP",
bloom_filter: true,
},
];

export default userAttributeSet;
Loading

0 comments on commit 7e327e3

Please sign in to comment.