Skip to content

Commit 20acb10

Browse files
authored
Merge pull request #1 from ergochat/ecdh_update.6
update to v2 API
2 parents d56adf9 + 73cb41c commit 20acb10

File tree

17 files changed

+1150
-287
lines changed

17 files changed

+1150
-287
lines changed

.check-gofmt.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
SOURCES="."
4+
5+
if [ "$1" = "--fix" ]; then
6+
exec gofmt -s -w $SOURCES
7+
fi
8+
9+
if [ -n "$(gofmt -s -l $SOURCES)" ]; then
10+
echo "Go code is not formatted correctly with \`gofmt -s\`:"
11+
gofmt -s -d $SOURCES
12+
exit 1
13+
fi

.github/dependabot.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "build"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "master"
7+
- "stable"
8+
push:
9+
branches:
10+
- "master"
11+
- "stable"
12+
13+
jobs:
14+
build:
15+
runs-on: "ubuntu-22.04"
16+
steps:
17+
- name: "checkout repository"
18+
uses: "actions/checkout@v3"
19+
- name: "setup go"
20+
uses: "actions/setup-go@v3"
21+
with:
22+
go-version: "1.23"
23+
- name: "make test"
24+
run: "make test"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ vendor/**
22

33
.DS_Store
44
*.out
5+
6+
*.swp

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
All notable changes to webpush-go will be documented in this file.
3+
4+
## [2.0.0] - 2025-01-01
5+
6+
* Update the `Keys` struct definition to store `Auth` as `[16]byte` and `P256dh` as `*ecdh.PublicKey`
7+
* `Keys` can no longer be compared with `==`; use `(*Keys.Equal)` instead
8+
* The JSON representation has not changed and is backwards and forwards compatible with v1
9+
* `DecodeSubscriptionKeys` is a helper to decode base64-encoded auth and p256dh parameters into a `Keys`, with validation
10+
* Update the `VAPIDKeys` struct to contain a `(*ecdsa.PrivateKey)`
11+
* `VAPIDKeys` can no longer be compared with `==`; use `(*VAPIDKeys).Equal` instead
12+
* The JSON representation is now a JSON string containing the PEM of the PKCS8-encoded private key
13+
* To parse the legacy representation (raw bytes of the private key encoded in base64), use `DecodeLegacyVAPIDPrivateKey`
14+
* Renamed `SendNotificationWithContext` to `SendNotification`, removing the earlier `SendNotification` API. (Pass `context.Background()` as the context to restore the former behavior.)

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.PHONY: test
2+
3+
test:
4+
go test .
5+
go vet .
6+
./.check-gofmt.sh

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# webpush-go
22

3-
[![Go Report Card](https://goreportcard.com/badge/github.com/SherClockHolmes/webpush-go)](https://goreportcard.com/report/github.com/SherClockHolmes/webpush-go)
4-
[![GoDoc](https://godoc.org/github.com/SherClockHolmes/webpush-go?status.svg)](https://godoc.org/github.com/SherClockHolmes/webpush-go)
3+
[![GoDoc](https://godoc.org/github.com/ergochat/webpush-go?status.svg)](https://godoc.org/github.com/ergochat/webpush-go)
54

65
Web Push API Encryption with VAPID support.
76

7+
This library is a fork of [SherClockHolmes/webpush-go](https://github.com/SherClockHolmes/webpush-go).
8+
89
```bash
9-
go get -u github.com/SherClockHolmes/webpush-go
10+
go get -u github.com/ergochat/webpush-go/v2
1011
```
1112

1213
## Example
@@ -19,20 +20,21 @@ package main
1920
import (
2021
"encoding/json"
2122

22-
webpush "github.com/SherClockHolmes/webpush-go"
23+
webpush "github.com/ergochat/webpush-go/v2"
2324
)
2425

2526
func main() {
2627
// Decode subscription
2728
s := &webpush.Subscription{}
2829
json.Unmarshal([]byte("<YOUR_SUBSCRIPTION>"), s)
30+
vapidKeys := new(webpush.VAPIDKeys)
31+
json.Unmarshal([]byte("<YOUR_VAPID_KEYS">), vapidKeys)
2932

3033
// Send Notification
3134
resp, err := webpush.SendNotification([]byte("Test"), s, &webpush.Options{
3235
Subscriber: "example@example.com",
33-
VAPIDPublicKey: "<YOUR_VAPID_PUBLIC_KEY>",
34-
VAPIDPrivateKey: "<YOUR_VAPID_PRIVATE_KEY>",
35-
TTL: 30,
36+
VAPIDKeys: vapidKeys,
37+
TTL: 3600, // seconds
3638
})
3739
if err != nil {
3840
// TODO: Handle error
@@ -46,15 +48,15 @@ func main() {
4648
Use the helper method `GenerateVAPIDKeys` to generate the VAPID key pair.
4749

4850
```golang
49-
privateKey, publicKey, err := webpush.GenerateVAPIDKeys()
51+
vapidKeys, err := webpush.GenerateVAPIDKeys()
5052
if err != nil {
5153
// TODO: Handle error
5254
}
5355
```
5456

5557
## Development
5658

57-
1. Install [Go 1.11+](https://golang.org/)
59+
1. Install [Go 1.20+](https://golang.org/)
5860
2. `go mod vendor`
5961
3. `go test`
6062

0 commit comments

Comments
 (0)