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

feat: POD Go library #33

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

feat: POD Go library #33

wants to merge 14 commits into from

Conversation

rrrliu
Copy link
Collaborator

@rrrliu rrrliu commented Jan 26, 2025

This PR adds a new Go library for the POD specification, and an example HTTP server application. Currently, the following fields are supported, with more support for types incoming.

  • String
  • Boolean
  • Int

POD operations are extremely fast, with signing and verification operations in a 500µs - 2ms range, benchmarked on a 2022 Macbook Pro with an M1 chip.

You can test a deployed version of the HTTP server under gopod.onrender.com. Sample commands for testing.

# Sign a POD
curl -X POST https://gopod.onrender.com/sign \
  -H 'Content-Type: application/json' \
  -d '{
  "entries": {
    "message": {
      "string": "Hello, world!"
    },
    "randomNum": {
      "int": 1231245
    },
    "isValid": {
        "boolean": true
    }
  }
}'

# Verify a POD (you can also try the response from above, also try tampering with the fields)
curl -X POST https://gopod.onrender.com/verify \
  -H 'Content-Type: application/json' \
  -d '{
    "entries": {
      "isValid": {"boolean": true},
      "message": {"string": "Greetings from Go"},
      "randomNum": {"int": 1231245}
    },
    "signature": "a465986417d2cdc0138123914ddcaf2c00dbd8623498e76515b610d434f256221dc11470c0a195fdbc1f4b9d2ab4144c4c972cd272e08bacb40bb5c0e8076d04",
    "signerPublicKey": "c433f7a696b7aa3a5224efb3993baf0ccd9e92eecee0c29a3f6c8208a9e81d9e"
}'

# Sign a POD, and get its Zupass URL
curl -X POST https://gopod.onrender.com/zupass \
  -H 'Content-Type: application/json' \
  -d '{
  "entries": {
    "message": {
      "string": "Hello, world!"
    },
    "randomNum": {
      "int": 1231245
    },
    "isValid": {
        "boolean": true
    }
  }
}'

@rrrliu rrrliu requested review from robknight and ludns January 26, 2025 08:34
@ludns ludns changed the title feat: POD Go library v1 feat: POD Go library Jan 26, 2025
return json.Unmarshal(v, &p.boolVal)
case "int":
p.kind = "int"
return json.Unmarshal(v, &p.intVal)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fairly sure that this will not work consistently with PODs serialized using our JavaScript library.

The JavaScript POD library can emit multiple representations for each POD value type, and so a compliant deserialization library must, in theory, support all of them. In the case of int values, this is not just a theoretical concern, as the default behaviour of the JavaScript POD library is to change the representation depending on the size and sign of the integer.

  • If the integer is below 56 bits in size, then the JSON number type is used
  • If the integer is above 56 bits in size, and positive, then a hexadecimal string is used
  • If the integer is above 56 bits in size, and negative, then a decimal string is used

The difficulty of implementing compliant deserialization libraries was one of the points of discussion when this was originally implemented. I suspect that our Rust implementation is also not compatible with the JavaScript one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants