Created
March 10, 2023 22:11
-
-
Save Gozala/a3472054d10cdb03d09eecd9ced328a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type ProviderDID = | |
| "did:web:web.storage" | |
| "did:web:nft.storage" | |
interface Principal { | |
did(): string | |
} | |
interface Space extends Principal { | |
} | |
abstract class Account implements Principal { | |
provider = { | |
add(provider: Provider, consumer: Space) { | |
const deal = provider.consumer.get(this) | |
deal.nb.consumer = consumer | |
deal.invoke() | |
} | |
} | |
} | |
interface Provider { | |
did(): ProviderDID | |
consumer: { | |
get: <T extends {}, U extends Account> (customer: U, nb?: T) => Subscription<Provider, U> | |
} | |
} | |
type Provision = { | |
consumer: Space, | |
provider: Provider, | |
// sponsor: Account | |
order: Order | |
} | |
abstract class Subscription<T extends Provider, U extends Account> { | |
can: "consumer/add" | |
with: T | |
nb: { | |
order: Order | |
consumer?: Space | |
} | |
invoke(consumer?: Space) { | |
this.nb.consumer = consumer | |
const provision = { | |
consumer: this.nb.consumer, | |
provider: this.with, | |
order: this.nb.order | |
} | |
TABLE.insert(provision) | |
} | |
} | |
type Order = string | |
// provider/get -> consumer/add | |
// consumer/add { consumer, order } | |
// web.storage | |
type W3Order<T extends Account> = CID<{ customer: T }> | |
// nft.storage | |
type NFTOrder<T extends Account> = CID<{ customer: T, timestamp: number }> | |
invoke({ | |
"iss": "did:key:agent", | |
"aud": "did:web:web.storage", | |
"att": [ | |
{ | |
"can": "access/authorize", | |
"nb": { | |
iss: "did:mailto:gozala", | |
att: [ | |
{ can: "store/*" }, | |
{ can: "upload/*" }, | |
] | |
} | |
} | |
] | |
}) // => { id: requestID } | |
// user clicked authorize maybe | |
// 1. We render page to the user to confirm authorization | |
// If you don't have a space we offer you to create one | |
// 2. We delegate attestations to the agent | |
// 3. We delegate store/* to the agent from account | |
invoke({ | |
att: [{ | |
can: "access/claim", | |
with: "did:web:web.storage", | |
nb: { | |
att: [{ can: "store/*" }] | |
} | |
}] | |
}) | |
const claimResult = [ | |
{ | |
iss: "did:web:web.storage", | |
aud: "did:key:agent", | |
att: [ | |
{ | |
can: "ucan/attest", | |
with: "did:web:web.storage", | |
}, | |
], | |
}, | |
{ | |
iss: "did:mailto:gozala", | |
aud: "did:key:agent", | |
att: [ | |
{ | |
can: "store/*", | |
with: "ucan:*", | |
}, | |
], | |
prf: [ | |
// { | |
// "consumer/add": "did:web:web.storage", | |
// } | |
// { | |
// iss: "did:key:space", | |
// aud: "did:mailto:gozala", | |
// att: [{ | |
// with: "ucan:*", | |
// can: "*" | |
// }] | |
// } | |
], | |
} | |
] | |
invoke({ | |
iss: "did:key:agent", | |
aud: "did:web:web.storage", | |
att: [ | |
{ | |
can: "access/authorize", | |
nb: { | |
iss: "did:mailto:gozala", | |
att: [{ can: "store/*" }, { can: "upload/*" }, { can: "consumer/add" }], | |
}, | |
}, | |
], | |
}) | |
// create space and call consumer/add | |
interface Subscription { | |
order: string | |
provider: Provider | |
customer: Account | |
consumer: { | |
add(consumer: Space): void | |
remove(consumer: Space): void | |
list(): Space[] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment