Skip to content

Instantly share code, notes, and snippets.

@michaelneale
Created May 22, 2023 07:35
Show Gist options
  • Save michaelneale/2e1e1a50444c5272784b29b7d457a414 to your computer and use it in GitHub Desktop.
Save michaelneale/2e1e1a50444c5272784b29b7d457a414 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>client1 sender</title>
<link href="https://cdn.jsdelivr.net/gh/TBD54566975/web5-omg@main/styles.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
</head>
<body>
<h>{TBD logo}</h>
<script type="module">
import { Web5 } from 'https://cdn.jsdelivr.net/npm/@tbd54566975/web5@0.7.4/dist/browser.mjs';
const { web5, did: myDid } = await Web5.connect();
var simpleMessageProtocol = {
"protocol": "http://simple-messaging-protocol3.xyz",
"types": {
"message": {
"schema": "http://simple-messaging-protocol3.xyz/schemas/message",
"dataFormats": ["text/plain"]
},
"messageResponse": {
"schema": "http://simple-messaging-protocol3.xyz/schemas/message-response",
"dataFormats": ["text/plain"]
}
},
"structure": {
"message": {
"$actions": [
{
"who": "anyone",
"can": "write"
},
{
"who": "recipient",
"of": "message",
"can": "read"
}
],
}
}
};
var { protocol, status } = await web5.dwn.protocols.configure({
message: {
definition: simpleMessageProtocol
}
});
console.log(status);
var client2 = ``; // get did from client1 html
// this creates a record and stores it in the user's local DWeb Node
const { record } = await web5.dwn.records.create({
data: "Hello World!",
message: {
protocol: "http://simple-messaging-protocol3.xyz",
schema: "http://simple-messaging-protocol3.xyz/schemas/message",
protocolPath: "message"
},
});
var { status } = await record.send(client2);
console.log(status);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Client 2 recipient</title>
<link href="https://cdn.jsdelivr.net/gh/TBD54566975/web5-omg@main/styles.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
</head>
<body>
<h>{TBD logo}</h>
<script type="module">
import { Web5 } from 'https://cdn.jsdelivr.net/npm/@tbd54566975/web5@0.7.4/dist/browser.mjs';
const { web5, did: myDid } = await Web5.connect();
console.log("client 2 did:", myDid);
var simpleMessageProtocol = {
"protocol": "http://simple-messaging-protocol3.xyz",
"types": {
"message": {
"schema": "http://simple-messaging-protocol3.xyz/schemas/message",
"dataFormats": ["text/plain"]
},
"messageResponse": {
"schema": "http://simple-messaging-protocol3.xyz/schemas/message-response",
"dataFormats": ["text/plain"]
}
},
"structure": {
"message": {
"$actions": [
{
"who": "anyone",
"can": "write"
},
{
"who": "recipient",
"of": "message",
"can": "read"
}
],
}
}
};
const { protocol, status } = await web5.dwn.protocols.configure({
message: {
definition: simpleMessageProtocol
}
});
console.log(status);
// This invocation will query the user's own DWeb Nodes
const { records } = await web5.dwn.records.query({
message: {
filter: {
protocol: "http://simple-messaging-protocol3.xyz",
},
},
});
console.log(records);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment