@graphprotocol/hypergraph 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/connect/auth-storage.d.ts.map +1 -0
- package/dist/connect/create-app-identity.d.ts.map +1 -0
- package/dist/connect/create-auth-url.d.ts.map +1 -0
- package/dist/connect/create-auth-url.js +35 -0
- package/dist/connect/create-auth-url.js.map +1 -0
- package/dist/connect/create-callback-params.d.ts.map +1 -0
- package/dist/connect/create-callback-params.js +17 -0
- package/dist/connect/create-callback-params.js.map +1 -0
- package/dist/connect/create-identity-keys.d.ts.map +1 -0
- package/dist/connect/identity-encryption.d.ts.map +1 -0
- package/dist/connect/index.d.ts.map +1 -0
- package/dist/connect/login.d.ts.map +1 -0
- package/dist/connect/parse-callback-params.d.ts.map +1 -0
- package/dist/connect/parse-callback-params.js +63 -0
- package/dist/connect/parse-callback-params.js.map +1 -0
- package/dist/connect/prove-ownership.d.ts.map +1 -0
- package/dist/connect/types.d.ts +57 -0
- package/dist/connect/types.d.ts.map +1 -0
- package/dist/connect/types.js +24 -0
- package/dist/connect/types.js.map +1 -0
- package/dist/entity/create.d.ts.map +1 -0
- package/dist/entity/decodedEntitiesCache.d.ts.map +1 -0
- package/dist/entity/delete.d.ts.map +1 -0
- package/dist/entity/entity.d.ts.map +1 -0
- package/dist/entity/entityRelationParentsMap.d.ts.map +1 -0
- package/dist/entity/findMany.d.ts.map +1 -0
- package/dist/entity/findMany.js +436 -0
- package/dist/entity/findMany.js.map +1 -0
- package/dist/entity/findOne.d.ts.map +1 -0
- package/dist/entity/getEntityRelations.d.ts.map +1 -0
- package/dist/entity/index.d.ts.map +1 -0
- package/dist/entity/relationParentsMap.d.ts.map +1 -0
- package/dist/entity/removeRelation.d.ts.map +1 -0
- package/dist/entity/types.d.ts +79 -0
- package/dist/entity/types.d.ts.map +1 -0
- package/dist/entity/types.js +2 -0
- package/dist/entity/types.js.map +1 -0
- package/dist/entity/update.d.ts.map +1 -0
- package/dist/identity/auth-storage.d.ts.map +1 -0
- package/dist/identity/get-verified-identity.d.ts.map +1 -0
- package/dist/identity/identity-encryption.d.ts.map +1 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/logout.d.ts.map +1 -0
- package/dist/identity/prove-ownership.d.ts.map +1 -0
- package/dist/inboxes/create-inbox.d.ts.map +1 -0
- package/dist/inboxes/get-list-inboxes.d.ts.map +1 -0
- package/dist/inboxes/index.d.ts.map +1 -0
- package/dist/inboxes/merge-messages.d.ts.map +1 -0
- package/dist/inboxes/message-encryption.d.ts.map +1 -0
- package/dist/inboxes/message-validation.d.ts.map +1 -0
- package/dist/inboxes/prepare-message.d.ts +31 -0
- package/dist/inboxes/prepare-message.d.ts.map +1 -0
- package/dist/inboxes/recover-inbox-creator.d.ts.map +1 -0
- package/dist/inboxes/recover-inbox-message-signer.d.ts.map +1 -0
- package/dist/inboxes/send-message.d.ts.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/messages/index.d.ts.map +1 -0
- package/dist/messages/signed-update-message.d.ts.map +1 -0
- package/dist/messages/types.d.ts.map +1 -0
- package/dist/space-events/accept-invitation.d.ts.map +1 -0
- package/dist/space-events/apply-event.d.ts.map +1 -0
- package/dist/space-events/create-inbox.d.ts.map +1 -0
- package/dist/space-events/create-invitation.d.ts.map +1 -0
- package/dist/space-events/create-space.d.ts.map +1 -0
- package/dist/space-events/delete-space.d.ts.map +1 -0
- package/dist/space-events/hash-event.d.ts.map +1 -0
- package/dist/space-events/index.d.ts.map +1 -0
- package/dist/space-info/decrypt-space-info.d.ts.map +1 -0
- package/dist/space-info/encrypt-and-sign-space-info.d.ts.map +1 -0
- package/dist/space-info/index.d.ts.map +1 -0
- package/dist/store-connect.d.ts.map +1 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/type/type.d.ts.map +1 -0
- package/dist/utils/automergeId.d.ts +9 -0
- package/dist/utils/automergeId.d.ts.map +1 -0
- package/dist/utils/automergeId.js +17 -0
- package/dist/utils/automergeId.js.map +1 -0
- package/dist/utils/generateId.d.ts +15 -0
- package/dist/utils/generateId.d.ts.map +1 -0
- package/dist/utils/generateId.js +18 -0
- package/dist/utils/generateId.js.map +1 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +35 -0
- package/src/connect/auth-storage.ts +67 -0
- package/src/connect/create-app-identity.ts +16 -0
- package/src/connect/create-auth-url.ts +42 -0
- package/src/connect/create-callback-params.ts +30 -0
- package/src/connect/create-identity-keys.ts +20 -0
- package/src/connect/identity-encryption.ts +232 -0
- package/src/connect/index.ts +10 -0
- package/src/connect/login.ts +114 -0
- package/src/connect/parse-auth-params.ts +37 -0
- package/src/connect/parse-callback-params.ts +67 -0
- package/src/connect/prove-ownership.ts +58 -0
- package/src/connect/types.ts +67 -0
- package/src/entity/create.ts +58 -0
- package/src/entity/decodedEntitiesCache.ts +38 -0
- package/src/entity/delete.ts +52 -0
- package/src/entity/entity.ts +26 -0
- package/src/entity/entityRelationParentsMap.ts +6 -0
- package/src/entity/findMany.ts +506 -0
- package/src/entity/findOne.ts +34 -0
- package/src/entity/getEntityRelations.ts +45 -0
- package/src/entity/hasValidTypesProperty.ts +8 -0
- package/src/entity/index.ts +8 -0
- package/src/entity/relationParentsMap.ts +6 -0
- package/src/entity/removeRelation.ts +21 -0
- package/src/entity/test.ts +0 -0
- package/src/entity/types.ts +100 -0
- package/src/entity/update.ts +58 -0
- package/src/entity/variant-schema.ts +677 -0
- package/src/identity/auth-storage.ts +57 -0
- package/src/identity/get-verified-identity.ts +53 -0
- package/src/identity/identity-encryption.ts +140 -0
- package/src/identity/index.ts +6 -0
- package/src/identity/logout.ts +8 -0
- package/src/identity/prove-ownership.ts +58 -0
- package/src/identity/types.ts +44 -0
- package/src/inboxes/create-inbox.ts +102 -0
- package/src/inboxes/get-list-inboxes.ts +52 -0
- package/src/inboxes/index.ts +10 -0
- package/src/inboxes/merge-messages.ts +28 -0
- package/src/inboxes/message-encryption.ts +35 -0
- package/src/inboxes/message-validation.ts +66 -0
- package/src/inboxes/prepare-message.ts +85 -0
- package/src/inboxes/recover-inbox-creator.ts +29 -0
- package/src/inboxes/recover-inbox-message-signer.ts +42 -0
- package/src/inboxes/send-message.ts +75 -0
- package/src/inboxes/types.ts +9 -0
- package/src/index.ts +13 -0
- package/src/key/create-key.ts +27 -0
- package/src/key/decrypt-key.ts +19 -0
- package/src/key/encrypt-key.ts +27 -0
- package/src/key/index.ts +4 -0
- package/src/key/key-box.ts +31 -0
- package/src/messages/decrypt-message.ts +13 -0
- package/src/messages/encrypt-message.ts +14 -0
- package/src/messages/index.ts +5 -0
- package/src/messages/serialize.ts +24 -0
- package/src/messages/signed-update-message.ts +84 -0
- package/src/messages/types.ts +506 -0
- package/src/space-events/accept-invitation.ts +36 -0
- package/src/space-events/apply-event.ts +150 -0
- package/src/space-events/create-inbox.ts +56 -0
- package/src/space-events/create-invitation.ts +41 -0
- package/src/space-events/create-space.ts +35 -0
- package/src/space-events/delete-space.ts +36 -0
- package/src/space-events/hash-event.ts +10 -0
- package/src/space-events/index.ts +8 -0
- package/src/space-events/types.ts +137 -0
- package/src/space-info/decrypt-space-info.ts +22 -0
- package/src/space-info/encrypt-and-sign-space-info.ts +50 -0
- package/src/space-info/index.ts +3 -0
- package/src/space-info/types.ts +7 -0
- package/src/store-connect.ts +504 -0
- package/src/store.ts +493 -0
- package/src/type/type.ts +25 -0
- package/src/types.ts +47 -0
- package/src/utils/assertExhaustive.ts +3 -0
- package/src/utils/automergeId.ts +18 -0
- package/src/utils/base58.ts +74 -0
- package/src/utils/generateId.ts +18 -0
- package/src/utils/hexBytesAddressUtils.ts +25 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/internal/base58Utils.ts +47 -0
- package/src/utils/internal/deep-merge.ts +38 -0
- package/src/utils/isRelationField.ts +9 -0
- package/src/utils/jsc.ts +94 -0
- package/src/utils/stringToUint8Array.ts +9 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import type { InboxSenderAuthPolicy } from '../inboxes/types.js';
|
|
4
|
+
import { canonicalize, generateId, hexToBytes, stringToUint8Array } from '../utils/index.js';
|
|
5
|
+
import type { Author, CreateSpaceInboxEvent } from './types.js';
|
|
6
|
+
|
|
7
|
+
export const createInbox = ({
|
|
8
|
+
author,
|
|
9
|
+
spaceId,
|
|
10
|
+
inboxId,
|
|
11
|
+
encryptionPublicKey,
|
|
12
|
+
secretKey,
|
|
13
|
+
isPublic,
|
|
14
|
+
authPolicy,
|
|
15
|
+
previousEventHash,
|
|
16
|
+
}: {
|
|
17
|
+
author: Author;
|
|
18
|
+
spaceId: string;
|
|
19
|
+
inboxId: string;
|
|
20
|
+
encryptionPublicKey: string;
|
|
21
|
+
previousEventHash: string;
|
|
22
|
+
secretKey: string;
|
|
23
|
+
isPublic: boolean;
|
|
24
|
+
authPolicy: InboxSenderAuthPolicy;
|
|
25
|
+
}): Effect.Effect<CreateSpaceInboxEvent, undefined> => {
|
|
26
|
+
const transaction = {
|
|
27
|
+
type: 'create-space-inbox' as const,
|
|
28
|
+
id: generateId(),
|
|
29
|
+
spaceId,
|
|
30
|
+
inboxId,
|
|
31
|
+
encryptionPublicKey,
|
|
32
|
+
secretKey,
|
|
33
|
+
isPublic,
|
|
34
|
+
authPolicy,
|
|
35
|
+
previousEventHash,
|
|
36
|
+
};
|
|
37
|
+
const signature = secp256k1.sign(
|
|
38
|
+
stringToUint8Array(canonicalize(transaction)),
|
|
39
|
+
hexToBytes(author.signaturePrivateKey),
|
|
40
|
+
{ prehash: true },
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// Create a SpaceEvent to create the inbox and sign it
|
|
44
|
+
const spaceEvent = {
|
|
45
|
+
transaction,
|
|
46
|
+
author: {
|
|
47
|
+
accountAddress: author.accountAddress,
|
|
48
|
+
signature: {
|
|
49
|
+
hex: signature.toCompactHex(),
|
|
50
|
+
recovery: signature.recovery,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
} satisfies CreateSpaceInboxEvent;
|
|
54
|
+
|
|
55
|
+
return Effect.succeed(spaceEvent);
|
|
56
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
|
|
4
|
+
import { canonicalize, generateId, hexToBytes, stringToUint8Array } from '../utils/index.js';
|
|
5
|
+
import type { Author, CreateInvitationEvent } from './types.js';
|
|
6
|
+
|
|
7
|
+
type Params = {
|
|
8
|
+
author: Author;
|
|
9
|
+
previousEventHash: string;
|
|
10
|
+
invitee: {
|
|
11
|
+
accountAddress: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const createInvitation = ({
|
|
16
|
+
author,
|
|
17
|
+
previousEventHash,
|
|
18
|
+
invitee,
|
|
19
|
+
}: Params): Effect.Effect<CreateInvitationEvent, undefined> => {
|
|
20
|
+
const transaction = {
|
|
21
|
+
id: generateId(),
|
|
22
|
+
type: 'create-invitation' as const,
|
|
23
|
+
inviteeAccountAddress: invitee.accountAddress,
|
|
24
|
+
previousEventHash,
|
|
25
|
+
};
|
|
26
|
+
const encodedTransaction = stringToUint8Array(canonicalize(transaction));
|
|
27
|
+
const signatureResult = secp256k1.sign(encodedTransaction, hexToBytes(author.signaturePrivateKey), {
|
|
28
|
+
prehash: true,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return Effect.succeed({
|
|
32
|
+
transaction,
|
|
33
|
+
author: {
|
|
34
|
+
accountAddress: author.accountAddress,
|
|
35
|
+
signature: {
|
|
36
|
+
hex: signatureResult.toCompactHex(),
|
|
37
|
+
recovery: signatureResult.recovery,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
|
|
4
|
+
import { canonicalize, generateId, hexToBytes, stringToUint8Array } from '../utils/index.js';
|
|
5
|
+
import type { Author, CreateSpaceEvent } from './types.js';
|
|
6
|
+
|
|
7
|
+
type Params = {
|
|
8
|
+
author: Author;
|
|
9
|
+
spaceId?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const createSpace = ({ author, spaceId }: Params): Effect.Effect<CreateSpaceEvent, undefined> => {
|
|
13
|
+
const transaction = {
|
|
14
|
+
type: 'create-space' as const,
|
|
15
|
+
id: spaceId ?? generateId(),
|
|
16
|
+
creatorAccountAddress: author.accountAddress,
|
|
17
|
+
};
|
|
18
|
+
const encodedTransaction = stringToUint8Array(canonicalize(transaction));
|
|
19
|
+
const signatureResult = secp256k1.sign(encodedTransaction, hexToBytes(author.signaturePrivateKey), {
|
|
20
|
+
prehash: true,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const event: CreateSpaceEvent = {
|
|
24
|
+
transaction,
|
|
25
|
+
author: {
|
|
26
|
+
accountAddress: author.accountAddress,
|
|
27
|
+
signature: {
|
|
28
|
+
hex: signatureResult.toCompactHex(),
|
|
29
|
+
recovery: signatureResult.recovery,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return Effect.succeed(event);
|
|
35
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
|
|
4
|
+
import { canonicalize, hexToBytes, stringToUint8Array } from '../utils/index.js';
|
|
5
|
+
|
|
6
|
+
import type { Author, DeleteSpaceEvent, SpaceEvent } from './types.js';
|
|
7
|
+
|
|
8
|
+
type Params = {
|
|
9
|
+
author: Author;
|
|
10
|
+
id: string;
|
|
11
|
+
previousEventHash: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const deleteSpace = ({ author, id, previousEventHash }: Params): Effect.Effect<SpaceEvent, undefined> => {
|
|
15
|
+
const transaction = {
|
|
16
|
+
type: 'delete-space' as const,
|
|
17
|
+
id,
|
|
18
|
+
previousEventHash,
|
|
19
|
+
};
|
|
20
|
+
const encodedTransaction = stringToUint8Array(canonicalize(transaction));
|
|
21
|
+
const signatureResult = secp256k1.sign(encodedTransaction, hexToBytes(author.signaturePrivateKey), {
|
|
22
|
+
prehash: true,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const event: DeleteSpaceEvent = {
|
|
26
|
+
transaction,
|
|
27
|
+
author: {
|
|
28
|
+
accountAddress: author.accountAddress,
|
|
29
|
+
signature: {
|
|
30
|
+
hex: signatureResult.toCompactHex(),
|
|
31
|
+
recovery: signatureResult.recovery,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
return Effect.succeed(event);
|
|
36
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { blake3 } from '@noble/hashes/blake3';
|
|
2
|
+
|
|
3
|
+
import { bytesToHex, canonicalize } from '../utils/index.js';
|
|
4
|
+
|
|
5
|
+
import type { SpaceEvent } from './types.js';
|
|
6
|
+
|
|
7
|
+
export const hashEvent = (event: SpaceEvent): string => {
|
|
8
|
+
const hash = blake3(canonicalize(event));
|
|
9
|
+
return bytesToHex(hash);
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './accept-invitation.js';
|
|
2
|
+
export * from './apply-event.js';
|
|
3
|
+
export * from './create-inbox.js';
|
|
4
|
+
export * from './create-invitation.js';
|
|
5
|
+
export * from './create-space.js';
|
|
6
|
+
export * from './delete-space.js';
|
|
7
|
+
export * from './hash-event.js';
|
|
8
|
+
export * from './types.js';
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { ParseError } from 'effect/ParseResult';
|
|
2
|
+
import * as Schema from 'effect/Schema';
|
|
3
|
+
import type { InvalidIdentityError } from '../identity/types.js';
|
|
4
|
+
import { InboxSenderAuthPolicy } from '../inboxes/types.js';
|
|
5
|
+
import { SignatureWithRecovery } from '../types.js';
|
|
6
|
+
|
|
7
|
+
export const EventAuthor = Schema.Struct({
|
|
8
|
+
accountAddress: Schema.String,
|
|
9
|
+
signature: SignatureWithRecovery,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export type EventAuthor = Schema.Schema.Type<typeof Author>;
|
|
13
|
+
|
|
14
|
+
export const SpaceMember = Schema.Struct({
|
|
15
|
+
accountAddress: Schema.String,
|
|
16
|
+
role: Schema.Union(Schema.Literal('admin'), Schema.Literal('member')),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export type SpaceMember = Schema.Schema.Type<typeof SpaceMember>;
|
|
20
|
+
|
|
21
|
+
export const SpaceInvitation = Schema.Struct({
|
|
22
|
+
inviteeAccountAddress: Schema.String,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export type SpaceInvitation = Schema.Schema.Type<typeof SpaceInvitation>;
|
|
26
|
+
|
|
27
|
+
export const SpaceInbox = Schema.Struct({
|
|
28
|
+
inboxId: Schema.String,
|
|
29
|
+
encryptionPublicKey: Schema.String,
|
|
30
|
+
isPublic: Schema.Boolean,
|
|
31
|
+
authPolicy: InboxSenderAuthPolicy,
|
|
32
|
+
secretKey: Schema.String,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export type SpaceInbox = Schema.Schema.Type<typeof SpaceInbox>;
|
|
36
|
+
|
|
37
|
+
export const SpaceState = Schema.Struct({
|
|
38
|
+
id: Schema.String,
|
|
39
|
+
invitations: Schema.Record({ key: Schema.String, value: SpaceInvitation }),
|
|
40
|
+
members: Schema.Record({ key: Schema.String, value: SpaceMember }),
|
|
41
|
+
removedMembers: Schema.Record({ key: Schema.String, value: SpaceMember }),
|
|
42
|
+
inboxes: Schema.Record({ key: Schema.String, value: SpaceInbox }),
|
|
43
|
+
lastEventHash: Schema.String,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export type SpaceState = Schema.Schema.Type<typeof SpaceState>;
|
|
47
|
+
|
|
48
|
+
export const CreateSpaceEvent = Schema.Struct({
|
|
49
|
+
transaction: Schema.Struct({
|
|
50
|
+
type: Schema.Literal('create-space'),
|
|
51
|
+
id: Schema.String,
|
|
52
|
+
creatorAccountAddress: Schema.String,
|
|
53
|
+
}),
|
|
54
|
+
author: EventAuthor,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export type CreateSpaceEvent = Schema.Schema.Type<typeof CreateSpaceEvent>;
|
|
58
|
+
|
|
59
|
+
export const DeleteSpaceEvent = Schema.Struct({
|
|
60
|
+
transaction: Schema.Struct({
|
|
61
|
+
type: Schema.Literal('delete-space'),
|
|
62
|
+
id: Schema.String,
|
|
63
|
+
previousEventHash: Schema.String,
|
|
64
|
+
}),
|
|
65
|
+
author: EventAuthor,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export type DeleteSpaceEvent = Schema.Schema.Type<typeof DeleteSpaceEvent>;
|
|
69
|
+
|
|
70
|
+
export const CreateInvitationEvent = Schema.Struct({
|
|
71
|
+
transaction: Schema.Struct({
|
|
72
|
+
type: Schema.Literal('create-invitation'),
|
|
73
|
+
id: Schema.String,
|
|
74
|
+
inviteeAccountAddress: Schema.String,
|
|
75
|
+
previousEventHash: Schema.String,
|
|
76
|
+
}),
|
|
77
|
+
author: EventAuthor,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export type CreateInvitationEvent = Schema.Schema.Type<typeof CreateInvitationEvent>;
|
|
81
|
+
|
|
82
|
+
export const CreateSpaceInboxEvent = Schema.Struct({
|
|
83
|
+
transaction: Schema.Struct({
|
|
84
|
+
type: Schema.Literal('create-space-inbox'),
|
|
85
|
+
id: Schema.String,
|
|
86
|
+
spaceId: Schema.String,
|
|
87
|
+
inboxId: Schema.String,
|
|
88
|
+
encryptionPublicKey: Schema.String,
|
|
89
|
+
secretKey: Schema.String,
|
|
90
|
+
isPublic: Schema.Boolean,
|
|
91
|
+
authPolicy: InboxSenderAuthPolicy,
|
|
92
|
+
previousEventHash: Schema.String,
|
|
93
|
+
}),
|
|
94
|
+
author: EventAuthor,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export type CreateSpaceInboxEvent = Schema.Schema.Type<typeof CreateSpaceInboxEvent>;
|
|
98
|
+
|
|
99
|
+
export const AcceptInvitationEvent = Schema.Struct({
|
|
100
|
+
transaction: Schema.Struct({
|
|
101
|
+
id: Schema.String,
|
|
102
|
+
type: Schema.Literal('accept-invitation'),
|
|
103
|
+
previousEventHash: Schema.String,
|
|
104
|
+
}),
|
|
105
|
+
author: EventAuthor,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
export type AcceptInvitationEvent = Schema.Schema.Type<typeof AcceptInvitationEvent>;
|
|
109
|
+
|
|
110
|
+
export const SpaceEvent = Schema.Union(
|
|
111
|
+
CreateSpaceEvent,
|
|
112
|
+
DeleteSpaceEvent,
|
|
113
|
+
CreateInvitationEvent,
|
|
114
|
+
AcceptInvitationEvent,
|
|
115
|
+
CreateSpaceInboxEvent,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
export type SpaceEvent = Schema.Schema.Type<typeof SpaceEvent>;
|
|
119
|
+
|
|
120
|
+
export const Author = Schema.Struct({
|
|
121
|
+
accountAddress: Schema.String,
|
|
122
|
+
signaturePublicKey: Schema.String,
|
|
123
|
+
signaturePrivateKey: Schema.String,
|
|
124
|
+
encryptionPublicKey: Schema.String,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
export type Author = Schema.Schema.Type<typeof Author>;
|
|
128
|
+
|
|
129
|
+
export class VerifySignatureError {
|
|
130
|
+
readonly _tag = 'VerifySignatureError';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export class InvalidEventError {
|
|
134
|
+
readonly _tag = 'InvalidEventError';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export type ApplyError = ParseError | VerifySignatureError | InvalidEventError | InvalidIdentityError;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { bytesToUtf8 } from '@noble/hashes/utils';
|
|
2
|
+
import * as Schema from 'effect/Schema';
|
|
3
|
+
import { decryptMessage } from '../messages/index.js';
|
|
4
|
+
import { hexToBytes } from '../utils/index.js';
|
|
5
|
+
import { SpaceInfoContent } from './types.js';
|
|
6
|
+
|
|
7
|
+
const decodeSpaceInfoContent = Schema.decodeSync(SpaceInfoContent);
|
|
8
|
+
|
|
9
|
+
export const decryptSpaceInfo = ({
|
|
10
|
+
spaceInfo,
|
|
11
|
+
secretKey,
|
|
12
|
+
}: {
|
|
13
|
+
spaceInfo: Uint8Array;
|
|
14
|
+
secretKey: string;
|
|
15
|
+
}) => {
|
|
16
|
+
const decrypted = decryptMessage({
|
|
17
|
+
nonceAndCiphertext: spaceInfo,
|
|
18
|
+
secretKey: hexToBytes(secretKey),
|
|
19
|
+
});
|
|
20
|
+
const spaceInfoContent = decodeSpaceInfoContent(JSON.parse(bytesToUtf8(decrypted)));
|
|
21
|
+
return spaceInfoContent;
|
|
22
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
2
|
+
import { utf8ToBytes } from '@noble/hashes/utils';
|
|
3
|
+
import * as Schema from 'effect/Schema';
|
|
4
|
+
import { encryptMessage } from '../messages/encrypt-message.js';
|
|
5
|
+
import { canonicalize, hexToBytes, stringToUint8Array } from '../utils/index.js';
|
|
6
|
+
import { SpaceInfoContent } from './types.js';
|
|
7
|
+
|
|
8
|
+
interface EncryptAndSignInfoParams {
|
|
9
|
+
accountAddress: string;
|
|
10
|
+
name: string;
|
|
11
|
+
secretKey: string;
|
|
12
|
+
signaturePrivateKey: string;
|
|
13
|
+
spaceId: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const encodeSpaceInfoContent = Schema.encodeSync(SpaceInfoContent);
|
|
17
|
+
|
|
18
|
+
export const encryptAndSignSpaceInfo = ({
|
|
19
|
+
accountAddress,
|
|
20
|
+
name,
|
|
21
|
+
secretKey,
|
|
22
|
+
signaturePrivateKey,
|
|
23
|
+
spaceId,
|
|
24
|
+
}: EncryptAndSignInfoParams) => {
|
|
25
|
+
const infoContent = encryptMessage({
|
|
26
|
+
message: utf8ToBytes(JSON.stringify(encodeSpaceInfoContent({ name: name }))),
|
|
27
|
+
secretKey: hexToBytes(secretKey),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const messageToSign = stringToUint8Array(
|
|
31
|
+
canonicalize({
|
|
32
|
+
accountAddress,
|
|
33
|
+
infoContent,
|
|
34
|
+
spaceId,
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const recoverySignature = secp256k1.sign(messageToSign, hexToBytes(signaturePrivateKey), { prehash: true });
|
|
39
|
+
|
|
40
|
+
const signature = {
|
|
41
|
+
hex: recoverySignature.toCompactHex(),
|
|
42
|
+
recovery: recoverySignature.recovery,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
infoContent,
|
|
47
|
+
accountAddress,
|
|
48
|
+
signature,
|
|
49
|
+
};
|
|
50
|
+
};
|