Skip to content

Commit

Permalink
TEMPPP: TO FIX
Browse files Browse the repository at this point in the history
TEMP STUFFF

ASDASDASD
  • Loading branch information
shahzadlone committed Jun 23, 2024
1 parent 77af4fc commit c74deba
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
96 changes: 96 additions & 0 deletions acp/identity/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright 2024 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

/*
Package identity provides defradb identity.
*/

package identity

import (
"fmt"

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"

"github.com/cyware/ssi-sdk/crypto"
"github.com/cyware/ssi-sdk/did/key"
// "github.com/lestrrat-go/jwx/jwk"
)

const (
// Custom source account address prefix
AccountAddressPrefix = "source"
)

// SourceIdentity holds the bits that make up an actor's unique identity.
// TODO-ACP: This will be merged with `Identity`.
type SourceIdentity struct {
// An actor's private key. Uses secp256k1 algorithm.
// PrivateJWK string

// An actor's corresponding public key address.
PublicKey string

// An actor's DID. Generated from the public key address.
DID string

// SourceHub Account Address. Generated from the public key address.
SourceAccountAddress string
}

// Generate generates a new source identity.
func Generate() (SourceIdentity, error) {
privateKey := secp256k1.GenPrivKey()

publicKey := privateKey.PubKey().Address()

accountAddress := types.AccAddress(publicKey)

sourceAccountAddress, err := bech32.ConvertAndEncode(AccountAddressPrefix, accountAddress)
if err != nil {
return SourceIdentity{}, err
}

did, err := key.CreateDIDKey(
crypto.SECP256k1,
// []byte(publicKey),
publicKey.Bytes(),
)

if err != nil {
return SourceIdentity{}, err
}

fmt.Println("000000000000000000000000000000000000")

Check failure on line 73 in acp/identity/generate.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
fmt.Println("string(privateKeyAddress.Bytes()) : ", string(privateKey.Bytes()))

Check failure on line 74 in acp/identity/generate.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
fmt.Println("string(privateKeyAddress.GetKey()) : ", string(privateKey.GetKey()))

Check failure on line 75 in acp/identity/generate.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
fmt.Println("string(privateKeyAddress.Key) : ", string(privateKey.Key))

Check failure on line 76 in acp/identity/generate.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
fmt.Println("privateKeyAddress.Key : ", privateKey.Key)

Check failure on line 77 in acp/identity/generate.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
fmt.Println("privateKeyAddress.GetKey() : ", privateKey.GetKey())

Check failure on line 78 in acp/identity/generate.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
fmt.Println("privateKeyAddress.String() : ", privateKey.String())

Check failure on line 79 in acp/identity/generate.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
fmt.Println("000000000000000000000000000000000000")

Check failure on line 80 in acp/identity/generate.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)

// Generate a new secp256k1 private key
// privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
// j, err := jwk.New(privateKey)
if err != nil {

Check failure on line 85 in acp/identity/generate.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

nilness: impossible condition: nil != nil (govet)
return SourceIdentity{}, err
}

return SourceIdentity{
// PrivateJWK: string(privateKey.GetKey()),
// PrivateJWK: j.Algorithm(),
PublicKey: publicKey.String(),
DID: did.String(),
SourceAccountAddress: sourceAccountAddress,
}, nil
}
25 changes: 25 additions & 0 deletions cli/acp_identity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2024 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package cli

import (
"github.com/spf13/cobra"
)

func MakeACPIdentityCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "identity",
Short: "Interact with the acp identity features of DefraDB instance",
Long: `Interact with the acp identity features of DefraDB instance`,
}

return cmd
}
39 changes: 39 additions & 0 deletions cli/acp_identity_new.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package cli

import (
"github.com/sourcenetwork/defradb/acp/identity"

Check failure on line 14 in cli/acp_identity_new.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

File is not `goimports`-ed with -local github.com/sourcenetwork/defradb (goimports)
"github.com/spf13/cobra"
)

func MakeACPIdentityNewCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "new",
Short: "Generate a new identity",
Long: `Generate a new identity
Example: generate a new identity:
defradb client acp identity new
`,
RunE: func(cmd *cobra.Command, args []string) error {
newIdentity, err := identity.Generate()
if err != nil {
return err
}

return writeJSON(cmd, newIdentity)
},
}

return cmd
}
6 changes: 6 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ func NewDefraCommand() *cobra.Command {
MakeACPPolicyAddCommand(),
)

identity := MakeACPIdentityCommand()
identity.AddCommand(
MakeACPIdentityNewCommand(),
)

acp := MakeACPCommand()
acp.AddCommand(
policy,
identity,
)

view := MakeViewCommand()
Expand Down

0 comments on commit c74deba

Please sign in to comment.