Skip to content

Commit 35aa142

Browse files
committed
dids for commits
1 parent 6cb2a1a commit 35aa142

5 files changed

Lines changed: 23 additions & 17 deletions

File tree

browser/lib/src/resource.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class Resource<C extends OptionalClass = any> {
117117

118118
throw new Error(
119119
'Invalid subject given to resource, must be a string, found ' +
120-
typeof subject,
120+
typeof subject,
121121
);
122122
}
123123

@@ -547,9 +547,10 @@ export class Resource<C extends OptionalClass = any> {
547547
public getCommitsCollectionSubject(): string {
548548
// For DID subjects (or other non-HTTP URIs) we can't derive the server
549549
// origin from the subject itself — use the store's server URL instead.
550-
const base = this.subject.startsWith('did:') || this.subject.startsWith('_')
551-
? this.store.getServerUrl()
552-
: this.subject;
550+
const base =
551+
this.subject.startsWith('did:') || this.subject.startsWith('_')
552+
? this.store.getServerUrl()
553+
: this.subject;
553554
const url = new URL('/commits', base);
554555
url.searchParams.append('property', commits.properties.subject);
555556
url.searchParams.append('value', this.subject);
@@ -599,9 +600,8 @@ export class Resource<C extends OptionalClass = any> {
599600
const commitsCollection = await this.store.fetchResourceFromServer(
600601
this.getCommitsCollectionSubject(),
601602
);
602-
const commitList = (commitsCollection.get(
603-
collections.properties.members,
604-
) ?? []) as string[];
603+
const commitList = (commitsCollection.get(collections.properties.members) ??
604+
[]) as string[];
605605

606606
const builtVersions: Version[] = [];
607607

@@ -841,7 +841,7 @@ export class Resource<C extends OptionalClass = any> {
841841
// the serialization signed here matches what the server will produce when
842842
// it verifies the signature. The server stores commit resources at
843843
// `{origin}/commits/{signature}`.
844-
const commitUrl = `${this.store.getServerUrl()}/commits/${this._lastLocalSignature}`;
844+
const commitUrl = `did:ad:commit:${this._lastLocalSignature}`;
845845
this.commitBuilder.setPreviousCommit(commitUrl);
846846
} else {
847847
const lastCommit = this.get(properties.commit.lastCommit)?.toString();
@@ -895,7 +895,9 @@ export class Resource<C extends OptionalClass = any> {
895895
}
896896

897897
const endpoint = this.getCommitEndpoint();
898-
const wasNew = this._pendingCommits.length > 0 && this._pendingCommits[0].previousCommit === undefined;
898+
const wasNew =
899+
this._pendingCommits.length > 0 &&
900+
this._pendingCommits[0].previousCommit === undefined;
899901

900902
let lastCommitId: string | undefined;
901903

@@ -1000,7 +1002,9 @@ export class Resource<C extends OptionalClass = any> {
10001002
});
10011003

10021004
// Keep a backup of the commit builder in case push fails.
1003-
const oldCommitBuilder = hasChanges ? this.commitBuilder.clone() : undefined;
1005+
const oldCommitBuilder = hasChanges
1006+
? this.commitBuilder.clone()
1007+
: undefined;
10041008
const wasNew = this.new;
10051009

10061010
try {

lib/src/commit.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,9 @@ impl Commit {
378378
.unwrap_or_default();
379379
if !writers.contains(&commit.signer) {
380380
writers.push(commit.signer.clone());
381-
applied.resource_new.set_unsafe(
382-
urls::WRITE.into(),
383-
writers.into(),
384-
);
381+
applied
382+
.resource_new
383+
.set_unsafe(urls::WRITE.into(), writers.into());
385384
}
386385
}
387386
}
@@ -625,7 +624,7 @@ impl Commit {
625624
#[tracing::instrument(skip(store))]
626625
pub async fn into_resource(&self, store: &impl Storelike) -> AtomicResult<Resource> {
627626
let commit_subject = match self.signature.as_ref() {
628-
Some(sig) => format!("internal:/commits/{}", sig),
627+
Some(sig) => format!("did:ad:commit:{}", sig),
629628
None => {
630629
let now = crate::utils::now();
631630
format!("internal:/commitsUnsigned/{}", now)

lib/src/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub async fn parse_json_ad_commit_resource(
233233
};
234234

235235
// Incoming commits do not have an @id field, we generate that from the signature.
236-
let commit_subject = format!("internal:/commits/{}", signature);
236+
let commit_subject = format!("did:ad:commit:{}", signature);
237237

238238
let resource =
239239
parse_json_ad_map_to_resource(json, store, Some(commit_subject), &ParseOpts::default())

lib/src/subject.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use url::Url;
44
/// The prefix for Agent DIDs: `did:ad:agent:`
55
pub const DID_AD_AGENT_PREFIX: &str = "did:ad:agent:";
66

7+
/// The prefix for Commit DIDs: `did:ad:commit:`
8+
pub const DID_AD_COMMIT_PREFIX: &str = "did:ad:commit:";
9+
710
/// The Subject of a Resource.
811
///
912
/// In Atomic Data, every subject is a URI.

server/src/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl SearchState {
8787

8888
let resources = store
8989
.all_resources(true)
90-
.filter(|resource| !resource.get_subject().as_str().contains("/commits/"));
90+
.filter(|resource| !resource.get_subject().as_str().contains("/commits/") && !resource.get_subject().as_str().starts_with("did:ad:commit:"));
9191

9292
for resource in resources {
9393
self.add_resource(&resource, store).await.map_err(|e| {

0 commit comments

Comments
 (0)