Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major change for ssb-custom-uri compatibility. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/from-sigil-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ const sigils = {
}

const safe64 = (s) => {
return s.replace(/\+/g, '-').replace(/\//g, '_')
//return s.replace(/\+/g, '-').replace(/\//g, '_')
return encodeURIComponent(s)
}

var semantics = g.createSemantics().addOperation('toSsbUri', {
sigilLink: function (sigil, base64, dot, commonAlgorithm) {
return [
'ssb',
let uri = [
sigil.toSsbUri(),
commonAlgorithm.toSsbUri(),
base64.toSsbUri()
].join(':')
].join('/')
return `ssb:${uri}`
},
sigil: function (str) {
return sigils[this.sourceString]
Expand All @@ -42,7 +43,7 @@ module.exports = (uri) => {
}

if (!module.parent) {
const uri = '%aUHk2iZgb7QPZVP5EWyJhW7EsZzgvlx3/VCrCOQYSZ0=.sha256'
const uri = '%EOgRe5ppgaugsqGyoWxJQ3QCFaGV7akjFUQ+9RR1jfk=.sha256'

console.log(module.exports(uri))
}
11 changes: 6 additions & 5 deletions lib/grammar/ssb-uri.ohm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ssbURI {


uriCommon = scheme commonType commonAlgorithm integerBase64
uriCommon = scheme commonType commonAlgorithm encodedBase64

queryPart = "?" uric*

Expand All @@ -14,7 +14,7 @@ ssbURI {

escaped = "%" hexDigit hexDigit

scheme = "ssb"
scheme = "ssb:"

unreserved = alnum | mark

Expand Down Expand Up @@ -62,7 +62,7 @@ ssbURI {

fragment = fragmentParts*

delimiter = ":"
delimiter = "/"

segmentPart = (delimiter segmentNzNc)+

Expand All @@ -74,7 +74,7 @@ ssbURI {
| "blob"
| "channel"

commonType = delimiter commonTypePart
commonType = commonTypePart

algorithm = delimiter unreserved*

Expand All @@ -95,6 +95,7 @@ ssbURI {
| "-"
| "_"
| "="
| "%"

integerBase64 = delimiter base64Parts*
encodedBase64 = delimiter base64Parts*
}
16 changes: 8 additions & 8 deletions lib/to-sigil-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ const sigils = {
}

const unsafe64 = (s) => {
return s.replace('-', '+').replace('_', '/')
return decodeURIComponent(s)
}

var semantics = g.createSemantics().addOperation('toSigilLink', {
uriCommon: function (scheme, commonType, commonAlgorithm, integerBase64) {
uriCommon: function (scheme, commonType, commonAlgorithm, encodedBase64) {
return [
commonType.toSigilLink(),
integerBase64.toSigilLink(),
encodedBase64.toSigilLink(),
'.',
commonAlgorithm.toSigilLink()
].join('')
},
commonType: function (delimiter, commonTypePart) {
commonType: function (commonTypePart) {
return commonTypePart.toSigilLink()
},
commonTypePart: function (part) {
Expand All @@ -37,11 +37,11 @@ var semantics = g.createSemantics().addOperation('toSigilLink', {
commonAlgorithmParts: function (part) {
return this.sourceString
},
integerBase64: function (delimiter, base64Parts) {
return base64Parts.toSigilLink().join('')
encodedBase64: function (delimiter, base64Parts) {
return unsafe64(base64Parts.toSigilLink().join(''))
},
base64Parts: function (part) {
return unsafe64(this.sourceString)
return this.sourceString
}
})

Expand All @@ -51,7 +51,7 @@ module.exports = (uri) => {
}

if (!module.parent) {
const uri = 'ssb:message:sha256:aUHk2iZgb7QPZVP5EWyJhW7EsZzgvlx3_VCrCOQYSZ0='
const uri = 'ssb:message/sha256/EOgRe5ppgaugsqGyoWxJQ3QCFaGV7akjFUQ%2B9RR1jfk%3D'

console.log(module.exports(uri))
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ssb-uri",
"version": "1.0.1",
"version": "2.0.0",
"description": "Uniform Resource Identifier (URI) utilities for Secure Scuttlebutt (SSB)",
"main": "index.js",
"scripts": {
Expand Down